By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Speed of PHP5, making PHP faster in general

P: n/a

I have tried out PHP 5 for the first time (with assistance from this
group -- thanks!).

The people I was working with have a site that uses lots of php
objects. They are having problems with speed. They had a vague idea
that PHP5 has improved handling of objects over PHP4, so it would
probably be faster also.

In fact it seems slower. We did a few timing loops, in which a a
number of objects were created and and members were accessed, and php
5 seemed to run about half the speed of php 4.

Is this in line with what other people are seeing ?

Is this an artifact of the beta -- that some debugging or logging is
being turned on by default which won't be when the real release comes
out ?

In general, what tricks can I do to make either PHP faster ? I
thought of compiling php with higher optimization flags, for instance.
Are there tweaks I can do to the php.ini file ? I'm interested in
anything, for any version of php.

--Rob
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi Rob!
On Wed, 18 Feb 2004 06:50:11 GMT, rg*@sdf.lonestar.org (Rob Ristroph)
wrote:

I have tried out PHP 5 for the first time (with assistance from this
group -- thanks!).

The people I was working with have a site that uses lots of php
objects. They are having problems with speed. They had a vague idea
that PHP5 has improved handling of objects over PHP4, so it would
probably be faster also.

In fact it seems slower. We did a few timing loops, in which a a
number of objects were created and and members were accessed, and php
5 seemed to run about half the speed of php 4.

Is this in line with what other people are seeing ?

Is this an artifact of the beta -- that some debugging or logging is
being turned on by default which won't be when the real release comes
out ?

In general, what tricks can I do to make either PHP faster ? I
thought of compiling php with higher optimization flags, for instance.
Are there tweaks I can do to the php.ini file ? I'm interested in
anything, for any version of php.
I think you will want to measure which parts of the page take longest
and optimise them. Most probably this will not be any opject handling
or member accessing but:
- database queries,
- regex on big strings
- copying of big objects
- loops

So you might gain maybe some percent by using precompilers, server/php
based caches etc, but you probably will reduce runtime by 50%, if you
the right database query gone, the right index, the right datamodel, a
better regex, or you work on a referenced object, or you cut out a
loop.

HTH, Jochen

--Rob


Jul 17 '05 #2

P: n/a
And recompile PHP for your architecture, i386, i686, AMD-K7, Athlon,
ATHLON-XP, ATHLON-MP, Intel Celeron, Intel P4, Intel P2, etc. Choosing the
right one can boost a lot.
to do so use the option : -march

gcc -march=[cpu] sourcecode

on gentoo, you must change in the file /etc/make.conf
CFLAGS = "-march=athlon-xp -pipe -O2"

Hope this help, mine was boosted up to 2-3 time faster when I recompile it.

Savut

"Jochen Daum" <jd@jdaum.de> wrote in message
news:v8********************************@4ax.com...
Hi Rob!
On Wed, 18 Feb 2004 06:50:11 GMT, rg*@sdf.lonestar.org (Rob Ristroph)
wrote:

I have tried out PHP 5 for the first time (with assistance from this
group -- thanks!).

The people I was working with have a site that uses lots of php
objects. They are having problems with speed. They had a vague idea
that PHP5 has improved handling of objects over PHP4, so it would
probably be faster also.

In fact it seems slower. We did a few timing loops, in which a a
number of objects were created and and members were accessed, and php
5 seemed to run about half the speed of php 4.

Is this in line with what other people are seeing ?

Is this an artifact of the beta -- that some debugging or logging is
being turned on by default which won't be when the real release comes
out ?

In general, what tricks can I do to make either PHP faster ? I
thought of compiling php with higher optimization flags, for instance.
Are there tweaks I can do to the php.ini file ? I'm interested in
anything, for any version of php.


I think you will want to measure which parts of the page take longest
and optimise them. Most probably this will not be any opject handling
or member accessing but:
- database queries,
- regex on big strings
- copying of big objects
- loops

So you might gain maybe some percent by using precompilers, server/php
based caches etc, but you probably will reduce runtime by 50%, if you
the right database query gone, the right index, the right datamodel, a
better regex, or you work on a referenced object, or you cut out a
loop.

HTH, Jochen

--Rob


Jul 17 '05 #3

P: n/a
And a powerful computer :D

Savut

"Jochen Daum" <jd@jdaum.de> wrote in message
news:v8********************************@4ax.com...
Hi Rob!
On Wed, 18 Feb 2004 06:50:11 GMT, rg*@sdf.lonestar.org (Rob Ristroph)
wrote:

I have tried out PHP 5 for the first time (with assistance from this
group -- thanks!).

The people I was working with have a site that uses lots of php
objects. They are having problems with speed. They had a vague idea
that PHP5 has improved handling of objects over PHP4, so it would
probably be faster also.

In fact it seems slower. We did a few timing loops, in which a a
number of objects were created and and members were accessed, and php
5 seemed to run about half the speed of php 4.

Is this in line with what other people are seeing ?

Is this an artifact of the beta -- that some debugging or logging is
being turned on by default which won't be when the real release comes
out ?

In general, what tricks can I do to make either PHP faster ? I
thought of compiling php with higher optimization flags, for instance.
Are there tweaks I can do to the php.ini file ? I'm interested in
anything, for any version of php.


I think you will want to measure which parts of the page take longest
and optimise them. Most probably this will not be any opject handling
or member accessing but:
- database queries,
- regex on big strings
- copying of big objects
- loops

So you might gain maybe some percent by using precompilers, server/php
based caches etc, but you probably will reduce runtime by 50%, if you
the right database query gone, the right index, the right datamodel, a
better regex, or you work on a referenced object, or you cut out a
loop.

HTH, Jochen

--Rob


Jul 17 '05 #4

P: n/a
>>>>> "Jochen" == Jochen Daum <jd@jdaum.de> writes:
Jochen>
Jochen> Hi Rob!
Jochen> On Wed, 18 Feb 2004 06:50:11 GMT, rg*@sdf.lonestar.org (Rob Ristroph)
Jochen> wrote:
Jochen>

I have tried out PHP 5 for the first time (with assistance from
this group -- thanks!).

The people I was working with have a site that uses lots of php
objects. They are having problems with speed. They had a vague
idea that PHP5 has improved handling of objects over PHP4, so it
would probably be faster also.

In fact it seems slower. We did a few timing loops, in which a a
number of objects were created and and members were accessed, and
php 5 seemed to run about half the speed of php 4.

Is this in line with what other people are seeing ?

Is this an artifact of the beta -- that some debugging or logging
is being turned on by default which won't be when the real release
comes out ?

In general, what tricks can I do to make either PHP faster ? I
thought of compiling php with higher optimization flags, for
instance. Are there tweaks I can do to the php.ini file ? I'm
interested in anything, for any version of php.

Jochen>
Jochen> I think you will want to measure which parts of the page take
Jochen> longest and optimise them. Most probably this will not be any
Jochen> opject handling or member accessing but:
Jochen> - database queries,
Jochen> - regex on big strings
Jochen> - copying of big objects
Jochen> - loops
Jochen>
Jochen> So you might gain maybe some percent by using precompilers,
Jochen> server/php based caches etc, but you probably will reduce
Jochen> runtime by 50%, if you the right database query gone, the
Jochen> right index, the right datamodel, a better regex, or you work
Jochen> on a referenced object, or you cut out a loop.
Jochen>
Jochen> HTH, Jochen

I agree with your observations. Eliminating database queries by
caching or grouping them together is always one to go after.

Unfortunately I am not sure that will help in the case of the site I
am working with. I think they have carefully put timing calls through
out and are sure that a lot of time is spent in object manipulation of
various sorts. I think it would be a lot of effort to rewrite the
whole thing, which is why I was interested in speeding up PHP or other
"magic bullet" type fixes.

I'll try the compilation flags that someone mentioned.

--Rob




Jul 17 '05 #5

P: n/a
It all depends on the code. PHP4 code that makes use of a lot of references
(in a tree structure, for instance), tends to be slow. If you pass objects
by value, then call their methods, it also slows things down in PHP4,
because a copy has to occur. PHP5 also manages memory better, so performance
improves under heavy load.

I have a script that generates ISO images. Running on PHP4, the Apache
process would suck in all available memory (only 128meg--this is my laptop)
until it crashes finally. On PHP5 the script runs smoothly.

Like the others said, you can probably gain more performance by focusing on
database queries. Avoid putting data from the database if you can. For
example, you know that the list of American states isn't going to change
every often, so you can just keep it in an array within the code. A good
rule of thumb is this: if you don't have a front-end page for modifying that
data, then it's probably not worthwhile to pull it from the database.

Uzytkownik "Rob Ristroph" <rg*@sdf.lonestar.org> napisal w wiadomosci
news:87************@rgristroph-austin.ath.cx...

I have tried out PHP 5 for the first time (with assistance from this
group -- thanks!).

The people I was working with have a site that uses lots of php
objects. They are having problems with speed. They had a vague idea
that PHP5 has improved handling of objects over PHP4, so it would
probably be faster also.

In fact it seems slower. We did a few timing loops, in which a a
number of objects were created and and members were accessed, and php
5 seemed to run about half the speed of php 4.

Is this in line with what other people are seeing ?

Is this an artifact of the beta -- that some debugging or logging is
being turned on by default which won't be when the real release comes
out ?

In general, what tricks can I do to make either PHP faster ? I
thought of compiling php with higher optimization flags, for instance.
Are there tweaks I can do to the php.ini file ? I'm interested in
anything, for any version of php.

--Rob

Jul 17 '05 #6

P: n/a
OK, I'm the guy Rob did this for. Couple of notes:
1. There were NO database queries or anything of the sort
2. We put together a class and simply performed a loop of 50
iterations that simply did $tmp_class = new class_name.
3. We used "microtime" to time this loop
4. It took almost exactly TWICE as long to perform the the above loop
in PHP5 vs. PHP4.
5. We used the latest php5 beta for this
6. We are wondering if maybe gdb/sdb code is incorporated in the beta
for php5 (which would understandably make it slower).

If this is truly the speed of php5, I'm afraid that we aren't ever
going to update to php5. It has great new features and we invested in
a book to adapt our code to it. However, if it is 1/2 the speed of
php4 - this really makes it unusable for us.

Anyone that might be able to tell us what we might do to make it at
least as fast as php4, we would sure love hear from you!

Thanks,
Dick
dg****@airlink.net
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<Q8********************@comcast.com>...
It all depends on the code. PHP4 code that makes use of a lot of references
(in a tree structure, for instance), tends to be slow. If you pass objects
by value, then call their methods, it also slows things down in PHP4,
because a copy has to occur. PHP5 also manages memory better, so performance
improves under heavy load.

I have a script that generates ISO images. Running on PHP4, the Apache
process would suck in all available memory (only 128meg--this is my laptop)
until it crashes finally. On PHP5 the script runs smoothly.

Like the others said, you can probably gain more performance by focusing on
database queries. Avoid putting data from the database if you can. For
example, you know that the list of American states isn't going to change
every often, so you can just keep it in an array within the code. A good
rule of thumb is this: if you don't have a front-end page for modifying that
data, then it's probably not worthwhile to pull it from the database.

Uzytkownik "Rob Ristroph" <rg*@sdf.lonestar.org> napisal w wiadomosci
news:87************@rgristroph-austin.ath.cx...

I have tried out PHP 5 for the first time (with assistance from this
group -- thanks!).

The people I was working with have a site that uses lots of php
objects. They are having problems with speed. They had a vague idea
that PHP5 has improved handling of objects over PHP4, so it would
probably be faster also.

In fact it seems slower. We did a few timing loops, in which a a
number of objects were created and and members were accessed, and php
5 seemed to run about half the speed of php 4.

Is this in line with what other people are seeing ?

Is this an artifact of the beta -- that some debugging or logging is
being turned on by default which won't be when the real release comes
out ?

In general, what tricks can I do to make either PHP faster ? I
thought of compiling php with higher optimization flags, for instance.
Are there tweaks I can do to the php.ini file ? I'm interested in
anything, for any version of php.

--Rob

Jul 17 '05 #7

P: n/a
Hi Dick!

On 19 Feb 2004 08:23:01 -0800, dg****@airlink.net (rg_air1) wrote:
OK, I'm the guy Rob did this for. Couple of notes:
1. There were NO database queries or anything of the sort
2. We put together a class and simply performed a loop of 50
iterations that simply did $tmp_class = new class_name.
3. We used "microtime" to time this loop
4. It took almost exactly TWICE as long to perform the the above loop
in PHP5 vs. PHP4.
5. We used the latest php5 beta for this
6. We are wondering if maybe gdb/sdb code is incorporated in the beta
for php5 (which would understandably make it slower).

If this is truly the speed of php5, I'm afraid that we aren't ever
going to update to php5. It has great new features and we invested in
a book to adapt our code to it. However, if it is 1/2 the speed of
php4 - this really makes it unusable for us.

Anyone that might be able to tell us what we might do to make it at
least as fast as php4, we would sure love hear from you!

I understand how you tested the speed and I thought I understood that
before. But are all your pages only containing object instantiations?
I believe what you tested is not gonna tell you much about the speed
of anything but the object instantiation of PHP4 and 5

HTH, Jochen

Thanks,
Dick
dg****@airlink.net
"Chung Leong" <ch***********@hotmail.com> wrote in message news:<Q8********************@comcast.com>...
It all depends on the code. PHP4 code that makes use of a lot of references
(in a tree structure, for instance), tends to be slow. If you pass objects
by value, then call their methods, it also slows things down in PHP4,
because a copy has to occur. PHP5 also manages memory better, so performance
improves under heavy load.

I have a script that generates ISO images. Running on PHP4, the Apache
process would suck in all available memory (only 128meg--this is my laptop)
until it crashes finally. On PHP5 the script runs smoothly.

Like the others said, you can probably gain more performance by focusing on
database queries. Avoid putting data from the database if you can. For
example, you know that the list of American states isn't going to change
every often, so you can just keep it in an array within the code. A good
rule of thumb is this: if you don't have a front-end page for modifying that
data, then it's probably not worthwhile to pull it from the database.

Uzytkownik "Rob Ristroph" <rg*@sdf.lonestar.org> napisal w wiadomosci
news:87************@rgristroph-austin.ath.cx...
>
> I have tried out PHP 5 for the first time (with assistance from this
> group -- thanks!).
>
> The people I was working with have a site that uses lots of php
> objects. They are having problems with speed. They had a vague idea
> that PHP5 has improved handling of objects over PHP4, so it would
> probably be faster also.
>
> In fact it seems slower. We did a few timing loops, in which a a
> number of objects were created and and members were accessed, and php
> 5 seemed to run about half the speed of php 4.
>
> Is this in line with what other people are seeing ?
>
> Is this an artifact of the beta -- that some debugging or logging is
> being turned on by default which won't be when the real release comes
> out ?
>
> In general, what tricks can I do to make either PHP faster ? I
> thought of compiling php with higher optimization flags, for instance.
> Are there tweaks I can do to the php.ini file ? I'm interested in
> anything, for any version of php.
>
> --Rob
>
>


--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #8

P: n/a
Uzytkownik "rg_air1" <dg****@airlink.net> napisal w wiadomosci
news:38**************************@posting.google.c om...
OK, I'm the guy Rob did this for. Couple of notes:
1. There were NO database queries or anything of the sort
2. We put together a class and simply performed a loop of 50
iterations that simply did $tmp_class = new class_name.
3. We used "microtime" to time this loop
4. It took almost exactly TWICE as long to perform the the above loop
in PHP5 vs. PHP4.
5. We used the latest php5 beta for this
6. We are wondering if maybe gdb/sdb code is incorporated in the beta
for php5 (which would understandably make it slower).


I was just commenting on performance optimization in general. Execution
speed probably shouldn't be the criteria for moving to PHP5, because any
gain will likely be small.

The reason why the PHP5 code takes longer to run is probably because it has
to look up the destructor of the class. PHP4 has no destructors.
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.