Azu Posted April 5, 2007 Share Posted April 5, 2007 I think that the way PHP works on my server right now is that every single time anybody opens up any page, it has to read the entire PHP file even the parts it doesn't use, and re compile the whole entire thing and then run that. This is horribly inefficient I think. Is there a way that I can just make it so that when the server starts up, it just compiles my PHP and opens it and then just leaves it open in memory instead of recompiling and opening and closing over and over and over? Using abyss server on windoz Please tell me how I can do this or give me some kind of hint as to how I can do this because I think it would help a lot but I don't really know how to benchmark it since whatever I put in PHP won't get ran until it has already read the php file, scanned the entire file for errors, and then compiled it and ran it, and by then it's to late to start the benchmark for it ^^ Quote Link to comment Share on other sites More sharing options...
gluck Posted April 5, 2007 Share Posted April 5, 2007 As far as I know PHP is an interpreted language. It is no compiled like C. And as far as optimization goes don't worry about it. For most cases the PHP engine has been written to perform to the best. You could though employ caching techniques and template engines etc. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 you can get a optimizer but your need a host that supports it, http://www.zend.com/products/zend_optimizer it basically it obfuscate and encode your entire project the code mainly used for protection Quote Link to comment Share on other sites More sharing options...
per1os Posted April 5, 2007 Share Posted April 5, 2007 To benchmark it you would use microtime www.php.net/microtime You start it at the top of the script ie: <?php $start = microtime(); // code here $end = microtime(); $totalTime = ($end - $start); print 'Your total time was ' . $totalTime . ' seconds!!'; ?> That is very accurate. As for compiling, unless you have an absurd amount of code like 4,000 + lines it should not effect the time displayed at all unless you have alot of error checks etc. I mean take a look at VBulletin, each page includes like 10 pages over like 7,000 lines of code plus tons of DB calls. PHP is very efficient. Quote Link to comment Share on other sites More sharing options...
$cripts Posted April 5, 2007 Share Posted April 5, 2007 i really see no point in doing this but try caching Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 normally i want the compleate reverse,, if the reason you want to keep the code in cache is becuase its slow, then i guess its tweak time. Quote Link to comment Share on other sites More sharing options...
Azu Posted April 6, 2007 Author Share Posted April 6, 2007 To benchmark it you would use microtime www.php.net/microtime You start it at the top of the script ie: <?php $start = microtime(); // code here $end = microtime(); $totalTime = ($end - $start); print 'Your total time was ' . $totalTime . ' seconds!!'; ?> That is very accurate. As for compiling, unless you have an absurd amount of code like 4,000 + lines it should not effect the time displayed at all unless you have alot of error checks etc. I mean take a look at VBulletin, each page includes like 10 pages over like 7,000 lines of code plus tons of DB calls. PHP is very efficient. Hi, that is what I normally use to benchmark my PHP, the problem is that the microtime will not start until my PHP has already been read from my hard disk drive, and has already been compiled, and already checked for errors so PHP knows whether or not to fall over and die, and already ran. By that time there is nothing left of the starting up to benchmark, only the time it takes for it to run once it has already started. By the way, is it faster to have all of my code in 1 file like it is now, or is it faster to put it in separate files and just include them based on if() clauses? And vBulletin is a very heavy forum. I am trying to make my website lightweight. It is a file called 1, around 200KB without comments, outside of my webserver directory, and I include it from a file called index.htm I am trying to make it secure ^^ and fast Thanks Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted April 6, 2007 Share Posted April 6, 2007 You're using the term compile incorrectly. PHP doesn't compile anything. Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted April 6, 2007 Share Posted April 6, 2007 Asides from that, I understand what you mean by compile. I think your best bet would be to generate HTML copies on the hour by cron jobs for pages that don't require input and don't have to be right up to date. Quote Link to comment Share on other sites More sharing options...
Azu Posted April 23, 2007 Author Share Posted April 23, 2007 I changed it to use fast-cgi mode instead of cgi and it seems to be more responsive now. And it doesn't keep opening and closing processes over and over. The problem with using cron jobs to do it is that the data comes from a mysql database that is updated many times a second, and if the data was an hour old, it would be bad, and there are to many pages to have them all generated every few minutes. I'm going to try making it so that when a page is accessed it will make a cache of it and if it is less then half a minute old it will just use the cache, so that popular pages don't have to be re-generated to often. Thanks for the advice everyone! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.