Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random fail with large amount of PHP files #18

Open
Sweetchuck opened this issue Jan 12, 2016 · 0 comments
Open

Random fail with large amount of PHP files #18

Sweetchuck opened this issue Jan 12, 2016 · 0 comments

Comments

@Sweetchuck
Copy link
Collaborator

For testing purposes a I tried to lint the /core directory of Drupal 8. It contains ~6200 PHP files.

It takes ~17sec to run this command:
time find ./ -type f \( -name '*.php' -or -name '*.inc' -or -name '*.install' -or -name '*.profile' \) -print0 | xargs -0 -P8 -n1 php -n -d sort_open_tag=Off -d asp_tags=Off -l

real    0m16.946s
user    1m10.360s
sys     0m24.196s

I am using the following configuration to achieve the same thing with grunt-phplint

grunt.initConfig({
    phplint: {
        core: {
            options: {
                cache: false,
                spawnLimit: 8,
                phpArgs: {
                    '-n': null,
                    '-d': [
                        'sort_open_tag=Off',
                        'asp_tags=Off'
                    ]
                }
            },
            files: [
                {
                    src:['core/**/*.{php,inc,module,install,profile}']
                }
            ]
        }
    }
});

The problem is that it randomly fails, but every time at a different PHP file.
The error message is:

Fatal error: Cannot read property 'on' of undefined
TypeError: Cannot read property 'on' of undefined
    at Object.PhpLintCommandWrapper.lintFile (/.../grunt-phplint/tasks/core/PhpLintCommandWrapper.js:24:20)
    at /.../grunt-phplint/tasks/core/PhpLintTask.js:73:11
    at Object.PhpLintTask._checkCached (/.../grunt-phplint/tasks/core/PhpLintTask.js:116:11)
    at Object.PhpLintTask._lintFile (/.../grunt-phplint/tasks/core/PhpLintTask.js:60:8)
    at bound (/.../grunt-phplint/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:573:19)
    at replenish (/.../grunt-phplint/node_modules/grunt-legacy-util/node_modules/async/lib/async.js:144:17)
    at /.../grunt-phplint/node_modules/grunt-legacy-util/node_modules/async/lib/async.js:156:29
    at /.../grunt-phplint/tasks/core/PhpLintTask.js:95:13
    at ChildProcess.<anonymous> (/.../grunt-phplint/tasks/core/PhpLintCommandWrapper.js:37:4)
    at emitTwo (events.js:87:13)

When I decrease the options.spawnLimit to 4 or less it works as expected.

I have added a console.log() to see what is there.

PhpLintCommandWrapper.prototype = {

    lintFile: function(filePath, done) {
        var cmdArgs = this._parseOptions(this.options.phpArgs),
            phpLintCmd = spawn(this.options.phpCmd, cmdArgs.concat([filePath])),
            output = "";

        if (typeof phpLintCmd.stdout === 'undefined') {
            console.log(JSON.stringify(Object.keys(phpLintCmd), null, 2));
        }

                // Line 24.
        phpLintCmd.stdout.on("data", function(data) {
            output += data;
        });
                // ...
    }
}
Running "phplint:core" (phplint) task
[D] Task source: tasks/phplint.js
[
  "domain",
  "_events",
  "_eventsCount",
  "_maxListeners",
  "_closesNeeded",
  "_closesGot",
  "connected",
  "signalCode",
  "exitCode",
  "killed",
  "spawnfile",
  "_handle",
  "spawnargs"
]
Fatal error: Cannot read property 'on' of undefined
TypeError: Cannot read property 'on' of undefined
    at Object.PhpLintCommandWrapper.lintFile (/.../grunt-phplint/tasks/core/PhpLintCommandWrapper.js:24:20)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant