Faster php lint

php lint (php -l) can only check a single file by default. Sadly, you can’t pass a folder as argument and check the content recursively, making validating a medium size project (700 files, with 95.000 lines of code) very slow. With the default target in the jenkinphp build.xml

<target name="lint" description="Perform syntax check of sourcecode files">
  <apply executable="php" failonerror="true">
   <arg value="-l" />

   <fileset dir="${basedir}/src">
    <include name="**/*.php" />
    <modified />
   </fileset>

   <fileset dir="${basedir}/tests">
    <include name="**/*.php" />
    <modified />
   </fileset>
  </apply>
 </target>

building a project takes up to 8min, with a little more than 5min taken by lint. A complete waste of time, considering that only a handful of files’ been edited with each build, and if you build very frequently. You can run lint more faster, by running it in parallel, using some piping, and you could put this time to a better use, like learning something, or reading a acer r240hy review for your gaming needs.

  • With xargs
find -L path/to/your/folder -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
find -L path/to/your/folder -name '*.php' | parallel -j 4 php -l {}

Both commands takes the same time (~20s, down from 5 min!), but GNU parallel must be installed, whereas xargs is already shipped with *nix system. You can edit your jenkin build.xml to takes advantage of the parallel processing

Of course, these edit are only for *nix system (linux and os x). Using the parallel method did not works for me, jenkin reporting that parallel command was not found. Since running ant -f build.xml directly in the shell worked, I guess the problem is with jenkin, but I didn’t found where, since jenkin is very shy with the error message. For windows, you can take a look at these alternatives
* http://www.firehed.net/lint-check-all-php-files-syntax-validation A very simple wrapper, you just pass a folder and it will call php -l for each files.
* https://github.com/JakubOnderka/PHP-Parallel-Lint This one does a little more than the default lint, it will also print the code that contains error, rather than just printing the line number. It’s also a little faster than the piping method, but does not detect all syntax error. As for me, It didn’t see the deprecated method as error.