Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate the syntax of PHP files more efficiently

Validating the syntax of a bunch of PHP files is SLOW

We use php -l file.php to validate the syntax of many php files as part of a continuous integration setup. We actually do something like: `find . -name "*.php" | xargs --max-args=1 php -l" because the php executable only takes one argument.

This is horrendously slow and mostly because it involves firing up a brand new parser / interpreter (not to mention process) for each PHP file in order to verify it's syntax and we have thousands.

Is there a faster way?

like image 553
Daniel Beardsley Avatar asked Jan 07 '13 09:01

Daniel Beardsley


1 Answers

What about adding a time in the search eg

`find . -mtime -7 -name "*.php" | xargs --max-args=1 php -l

to the find command to only validate the files that have been modified on the last week?

I am presuming most of your code base does not change every few days?

Updated

You might also want to try the -newer flag

`find . -newer /path/to/file -name "*.php" | xargs --max-args=1 php -l

it finds all files newer than the one given, very handy, especially if your version control changes a certain system file every time you checkout alternatively use:

touch -t 201303121000 /path/to/file 

to create a dummy file for use with -newer

like image 73
CodeMonkey Avatar answered Oct 24 '22 07:10

CodeMonkey