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.

  • With xargs
    find -L path/to/your/folder -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l
  • With GNU parallel
    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