Skip to content

Implement GH-10024: support linting multiple files at once using php -l #10710

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

Closed
wants to merge 5 commits into from

Conversation

nielsdos
Copy link
Member

Closes GH-10024

This is supported in both the CLI and CGI modes. For CLI this required little changes.

For CGI, the tricky part was that the options parsing happens inside the loop. This means that options passed after the -l flag were previously simply ignored. As we now re-enter the loop we would parse the options again, and if they are handled but don't set the script name, then CGI will think you want to read from standard in. To keep the same "don't parse options" behaviour I simply wrapped the options handling inside an if.

@staabm
Copy link
Contributor

staabm commented Feb 26, 2023

Thank you for working on it 🙏.

Could you give an indication what the perf difference is linting e.g. 2 or 3 (or a few) files in a row vs. in a single process?

The thesis of the initial issue was, that it should be way faster.

@nielsdos
Copy link
Member Author

Sure.

For the root folder of Wordpress (15 files) I get 0.013s for linting them all at once, and I get 0.154s when linting them one by one.

For two files I get 0.009s for linting them all at once, and 0.018s for linting them one by one. It's not a coincidence that it's twice as much for linting one by one because the overhead outweighs everything else in this case.

So yeah, it's better for performance.

@staabm
Copy link
Contributor

staabm commented Mar 15, 2023

Can this PR land in PHP 8.2.x or can such a change only be done in 8.3.x

@nielsdos
Copy link
Member Author

Can this PR land in PHP 8.2.x or can such a change only be done in 8.3.x

It's a new feature so unfortunately you'll have to wait as this will land in 8.3

@staabm
Copy link
Contributor

staabm commented Jun 9, 2023

@nielsdos any chance this could slip into 8.3?

@nielsdos nielsdos requested a review from iluuu1994 June 9, 2023 15:15
@nielsdos
Copy link
Member Author

nielsdos commented Jun 9, 2023

@nielsdos any chance this could slip into 8.3?

I've re-requested a review.

@staabm
Copy link
Contributor

staabm commented Jun 14, 2023

Anyone else could review the changes? Would be great this PR could be part of PHP 8.3, as it is the foundation for speeding up php linting tools which can potentially save a lot of CI time

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, thanks @nielsdos!

Array
(
[0] => No syntax errors detected in %s012_good.test.php
[1] => No input file specified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is a bit confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this comes from lines 2457-2460. Either we can change the error message for CGI in general, or special case the linting case. I think changing the message in general might be dangerous for BC though.

Array
(
[0] => No syntax errors detected in %s012_good.test.php
[1] => No input file specified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This differs in behavior with CLI, in that it aborts when a file is not found. Is this a limitation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we'd need to change error handling in lines 2451-2488: if a file cannot be opened or accessed CGI aborts. But I'm not sure if we should special case it because it will make things more complicated and possibly slow down regular use of CGI. Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt linting is often used with php-cgi, so this should be ok.

nielsdos added 4 commits June 29, 2023 21:06
…hp -l

This is supported in both the CLI and CGI modes. For CLI this required
little changes.

For CGI, the tricky part was that the options parsing happens inside the
loop. This means that options passed after the -l flag were previously
simply ignored. As we now re-enter the loop we would parse the options
again, and if they are handled but don't set the script name, then CGI
will think you want to read from standard in. To keep the same "don't
parse options" behaviour I simply wrapped the options handling inside an
if.
@nielsdos nielsdos closed this in f16b34f Jul 5, 2023
@staabm
Copy link
Contributor

staabm commented Jul 5, 2023

thank you so much to anyone who made this possible!!

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

Successfully merging this pull request may close these issues.

support linting multiple files at once using php -l
3 participants