Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

http://fr2.php.net/php_check_syntax 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
add comment

Your Answer

 
discard

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.