Scanning a Directory For PHP Errors

My fellow web geeks might find this script, php-check download home on the range movie , useful. It recursively scans a directory checking PHP files for syntax errors.

Just copy it somewhere in your path (like /usr/local/bin) and chmod it to 755.

I wrote the script because I edit PHP using Notepad++, so it’s easy for small typos to enter my scripts. I needed a quick way to scan a directory after uploading revised files.
I wrote it in PHP so that those who need it will also know how to customize it.

[php]
#!/usr/bin/php
?php // php-check version 1.0 // recursively scans a directory for .php files and runs php ‑l on // them (php ‑l checks for PHP syntax errors) // revisions at http://glenandpaula.com/wordpress/archives/2007/10/31/scanning-a-directory-for-php-errors/ if (php_sapi_name()!=‘cli’) { die(“This utility can only be run from the command line.\n”); } $counter=0; $errors=false; function scan_dir($dir) { $counter=0; $dh=opendir($dir); while ($file=readdir($dh)) { if ($file==’.’ || $file==’..’) continue; if (is_dir($dir.’/’.$file)) { $counter+=scan_dir($dir.’/’.$file); } else { if (substr($file, strlen($file) — 4) == ‘.php’) { $counter++; $output=shell_exec(“/usr/bin/php ‑l $dir/$file 2>&1”);
if (substr($output,0,2)!=‘No’) { // skips the “No syntax errors in …” message
$errors=true;
echo $output;
}
}

}
}
return $counter;
}
if ($argc!=2) {
die(“Usage: php-check dirname (usually php-check .)\n”);
}

if (!is_dir($argv[1])) {
die(“Argument must be a directory. The most common usage is php-check .\n”);
}

$counter=scan_dir($argv[1]);

echo “$counter files checked\n”;
exit($errors);
?>
[/php]

This is a quick and dirty script — there are probably some bugs in it. User beware.

If you find it helpful, you might also want to check out scripts like PHP CodeSniffer

or PHP Beautifier.download robot chicken star wars dvd

2,780 thoughts on “Scanning a Directory For PHP Errors”

  1. Pingback: Jordan 11 Low
  2. Pingback: curry one low blue
  3. Pingback: Buy TOMS Shoes
  4. Pingback: toms Sko billig
  5. Pingback: buy Low 11s
  6. Pingback: jordan store
  7. Pingback: ray ban optical
  8. Pingback: toms skor sverige
  9. Pingback: nike free sneakers
  10. Pingback: b&l ray ban
  11. Pingback: Low 11s online
  12. Pingback: buy jordan 11 Low
  13. Pingback: Billige Toms Sko
  14. Pingback: buy jordan 11 Low
  15. Pingback: Jordan 11 Low
  16. Pingback: women toms
  17. Pingback: Toms
  18. Pingback: pre order Low 11s
  19. Pingback: Toms Skor norge
  20. Pingback: Low 11s
  21. Pingback: toms men
  22. Pingback: Low 11s
  23. Pingback: ray bans cheap
  24. Pingback: Burberry Handbags
  25. Pingback: cheap curry shoes
  26. Pingback: sunglasses ray ban

Leave a Reply