Speed up PHP linting with xargs

Most of us use Jenkins to continuously integrate our projects with every commit to the repository, but when it comes with PHP most of the time is spent “linting“.

This action is badly slow and if your project has a lot of files this will take a good percentage of your build time. A really good approach could be executing this task with different files in parallel. For this you can use the powerful xargs command with -P0, which allows xargs to run as many processes as possible at a time.

find codefolder/ -name "*.php" -print0 | xargs -0 -n1 -P0 php -l

So the final snippet for your Ant based project will be:

<target name="lint">
  <exec executable="sh" failonerror="true">
      <arg value="-c" />
      <arg value="find ${project.paths.php.space-separated} -name *.php -print0 | xargs -0 -n1 -P0 php -l"/>