Page 1 of 1

Syntax Checking

Posted: Fri Feb 03, 2006 1:43 pm
by phpCCore Brad
I've noticed that if I use command line php syntax checking it causes major load time on my script. However, since I develop for mostly php 4 users there is no built in command for file syntax checking. So I was wondering if anyone has any ideas as to how I could possibly run a syntax checking at a decent speed.

Thanks,
Brad Bridges

The following is the function I was using that causes lag:

Code: Select all

function def_checkFile($filename,$checkSyntax = false){

   if (!file_exists($filename)) {
   	return false;
   }
  
   if ($checkSyntax) {
   	   $command = 'php -l ' . $filename;
  	   $output = shell_exec($command);
	   if (strpos($output, 'No syntax errors detected in') !== false){
		   return(true);   
	   } else {
		   return(false);   
	   } 
   }
   return true;  
}

Posted: Fri Feb 03, 2006 1:58 pm
by josh
There is http://us2.php.net/manual/en/function.p ... syntax.php


but...
For technical reasons, this function is deprecated and removed from PHP. Instead, use php -l somefile.php from the commandline.
I'm guessing any way you're going to find to do it is going to be slower then php -l just because of the fact -l is part of PHP itself.

Posted: Sat Feb 04, 2006 10:46 am
by phpCCore Brad
Also that is a php 5 function.

Posted: Sat Feb 04, 2006 12:37 pm
by josh
How long does php -l take? It runs at about the same speed it takes the page to run for me, which is not very noticable... you could cache the result of this along with a checksum of the file and only run it when the page has changed

Posted: Sat Feb 04, 2006 7:03 pm
by m3mn0n
What you use is your best bet. Unless there is some other obscure way that I don't know about.

What exactly did you mean by slow? How large are the files you are processing and what is the average speed of the syntax check?

Posted: Thu Feb 16, 2006 3:12 pm
by phpCCore Brad
Well, it's not that the files are large its that there could be hundreds included. The slowness I state comes up that after it does that many files it adds seconds to load time. On a script that normally loads in MS.