Syntax Checking

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpCCore Brad
Forum Commoner
Posts: 47
Joined: Sun Dec 04, 2005 5:46 pm
Location: Michigan, USA
Contact:

Syntax Checking

Post 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;  
}
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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.
phpCCore Brad
Forum Commoner
Posts: 47
Joined: Sun Dec 04, 2005 5:46 pm
Location: Michigan, USA
Contact:

Post by phpCCore Brad »

Also that is a php 5 function.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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?
phpCCore Brad
Forum Commoner
Posts: 47
Joined: Sun Dec 04, 2005 5:46 pm
Location: Michigan, USA
Contact:

Post 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.
Post Reply