Page 1 of 1
Improve/Optimize PHP performance
Posted: Sun Feb 06, 2011 1:23 pm
by rahulgolwalkar
Hi,
PHP is an interpreted language and hence it is slow as compared to some other compiled ones. Can anyone give some tips on improving the performance of PHP and/or optimizing the PHP in any way/manner would do.
Some one suggested me of using HIP HOP.
Can anyone enlighten on general increasing the performance of PHP as such the number of users on my server are increasing and it is causing delays for the visitors .
Thank You .
Re: Improve/Optimize PHP performance
Posted: Sun Feb 06, 2011 3:40 pm
by gooney0
I'd recommend "apc"
http://php.net/manual/en/book.apc.php
It's an Apache module.
Here is how it works:
A script is accessed as usual. APC saves a complied version of the script in memory. The next time that script is accessed it (optionally) checks to see if the script has changed. If not it runs the compiled version it has saved in memory.
This means that frequently used scripts don't have to be complied each time. They only have to be executed.
How much faster will depend of course. Large scripts speed up quite well, while DB heavy scripts do not.
Other tips:
Properly index your DB tables. Try your queries in the client using "EXPLAIN" to be sure you're hitting the indexes you intend to use.
Adjust Apache if you have too many clients at once they could be waiting for threads.
Cleanup PHP code. Combine javascripts and style sheets.
Make the homepage static. Use PHP to create and cache a static HTML front page. This is probably the page that gets the most hits. When you update the data have the backend recreate the static page.
Re: Improve/Optimize PHP performance
Posted: Mon Feb 07, 2011 8:27 am
by Darhazer
rahulgolwalkar wrote:Hi,
PHP is an interpreted language and hence it is slow as compared to some other compiled ones. Can anyone give some tips on improving the performance of PHP and/or optimizing the PHP in any way/manner would do.
Some one suggested me of using HIP HOP.
Can anyone enlighten on general increasing the performance of PHP as such the number of users on my server are increasing and it is causing delays for the visitors .
Thank You .
Profile your code (using xhprof for example) to see what is slow. Maybe the delay have nothing to do with PHP (usually database is slower), or you are using some really slow functions

But optimization without profiling is meaningless thing to do.
Re: Improve/Optimize PHP performance
Posted: Mon Feb 07, 2011 11:26 am
by greyhoundcode
I'm sure this link has been posted here before but it's relevant and might be of interest to you:
Rasmus Lerdorf on HipHop.
Re: Improve/Optimize PHP performance
Posted: Mon Feb 07, 2011 2:44 pm
by pickle
How many users do you have? There's a distinct possibility the problem isn't with PHP, but rather how you're using it.
Re: Improve/Optimize PHP performance
Posted: Mon Feb 07, 2011 4:47 pm
by greyhoundcode
jcourtenay wrote:One of the best ways to do this is to tweak the script timeout limit so that scripts run smoothly on your site.
...
