Improve/Optimize PHP performance

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
rahulgolwalkar
Forum Newbie
Posts: 1
Joined: Sun Feb 06, 2011 1:16 pm

Improve/Optimize PHP performance

Post 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 .
gooney0
Forum Commoner
Posts: 56
Joined: Fri Jan 21, 2011 1:40 pm
Location: Reston, VA

Re: Improve/Optimize PHP performance

Post 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.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Improve/Optimize PHP performance

Post 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.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Improve/Optimize PHP performance

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Improve/Optimize PHP performance

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Improve/Optimize PHP performance

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