How to speed up php?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've got a problem with performance...

I'm working on a fairly slow embedded platform (a 200 MHz ARM board).  
We run a browser and a webserver on the same platform.

I've timed the performance, and the webserver takes between 5 and 6  
seconds to generate the page.  Most of this time is spent running php.  
The webserver is buysbox's httpd daemon, which invokes php every time a  
page is served.

I'm guessing that I could save a few seconds of this time by keeping php  
resident in memory so rather than incurring the overhead of starting it  
every time.

So... Is this a right guess?  How long does it take to load php?  Is  
there some way to daemonize PHP so that it doesn't have to load up every  

I am looking for any and all suggestions to speed this beast up....


Re: How to speed up php?

CptDondo wrote:

Quoted text here. Click to load it

My advice would be to stick a fresh copy of debian 3.1 stable on the
box, no X (no gui at all), install apache and php and then save your
php scripts onto it and load them via a network connection, if you
havent used an OS without a gui before there will be some learning
involved but its useful and there are lots of useful sites out there
with step by step, and to install apache and php you just simply type
apt-get install apache. that wil download the files and run the

i have never heard of buysboxs webserver but i am sure its rubbish.


Re: How to speed up php?

flamer wrote:
Quoted text here. Click to load it

Your advice is worthless. If you have never heard of busybox, then you  
know nothing about embedded Linux.


Re: How to speed up php?

Colin Fine wrote:

Quoted text here. Click to load it


Yup.... I wasn't going to engage, but I submitted the original patches  
to let busybox httpd run php cgi...  (the developers chose not to use  
them and instead worked up their own, cleaner solution.  Still, I like  
to think I prodded them into it.  :-)  ) I find it ironic that now I am  
not going to use busybox because of performance issues....


Re: How to speed up php?

On Thu, 19 Oct 2006 16:29:46 -0700, CptDondo wrote:
Quoted text here. Click to load it

Admittedly I don't deal with embedded platforms as a rule, but you might
like to have a look at using lighttpd < with PHP
running under FastCGI, which should take out much of the process
initialisation overhead that you're noticing now. If you have some spare
RAM available (doubtful, I know, given the nature of the platform), you
could also consider using an opcode cache like APC
< or eAccelerator
< , which would save the script(s) being parsed on
each request.

Having said that, it may just be that the PHP script itself is taking some
time to execute, in which case there may not be much you can do.
Another option available to you is to profile the PHP script using
xdebug 2 < , which can generate cachegrind files you can
then view in KCacheGrind or something similar on your development machine
-- this might help lock down any bottlenecks within the script itself.

Not sure how much more advice I can give you, not being an expert in the
field, but hopefully something here can help. :)


Adam Harvey

To e-mail: don't make an example out of me!

Re: How to speed up php?

Adam Harvey wrote:
Quoted text here. Click to load it

Woo hoo!  That took the generation time from about 6 seconds to just  
under a second.  Some of the complicated pages still take a couple of  
seconds, but that's OK.  Whee!

Quoted text here. Click to load it

Currently I have 32 MB, but I can add more for the production if it is  



Re: How to speed up php?

CptDondo wrote:
Quoted text here. Click to load it

PHP initialization is fairly expensive. A couple megs of code have to
be loaded into ram; the ini file has to be parsed; a couple thousand
built-in functions have to be initialized (a lot of memory allocation).
Depending on the performance of the storage system, it could take a

Quoted text here. Click to load it

As suggested, use FastCGI to avoid having to start PHP every time.
Beyond that I don't know what more could be done. Since it's an
embedded system, there probably isn't a whole lot of memory to go
around. The low performance could simply be the result of swapping.
Five seconds to generate a page sounds excessive even on a slow CPU. It
could also simply be that your PHP code is inefficient.

Site Timeline