Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In PHP I am making a kind of bot which dynamically includes a few different PHP files. Since these PHP files may change, I would like the files to be checked for syntax/parse errors before the include() or require() is run. Would this be possible? If so, how?

share|improve this question
up vote 0 down vote accepted

use the php executeable with the -l argument from the command line. you can do that using a system call, or shell_exec

share|improve this answer
Thanks. I am assuming that there is no more efficient way of achieving this, since I've noticed that the exec("php -l {$file}"); pauses the script for a second. – Dead-i Jun 4 '12 at 6:31 is your help. Check the examples !

share|improve this answer
Note: For technical reasons, this function is deprecated and removed from PHP. Instead, use php -l somefile.php from the commandline. – The Shurrican May 26 '12 at 19:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.