Jump to content

[SOLVED] Optimizing PHP to not recompile


Azu

Recommended Posts

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 ^^

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 3 weeks later...

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.