473,242 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

Speed of PHP5, making PHP faster in general


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
8 2899
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
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
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
>>>>> "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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Neuruss | last post by:
It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. I just wonder what do you all think? Will Python...
4
by: Joanna Carter \(TeamB\) | last post by:
Hi gurus. Does anyone have any experience as to whether .NET 2.0 will be any faster executing than .NET 1.1 ? We are looking at starting a new project in .NET and are getting feedback from...
53
by: Krystian | last post by:
Hi are there any future perspectives for Python to be as fast as java? i would like to use Python as a language for writing games. best regards krystian
5
by: pt | last post by:
Hi, i am wonderng what is faster according to accessing speed to read these data structure from the disk in c/c++ including alignment handling if we access it on little endian system 32 bits...
4
by: RS | last post by:
Hi all, I was told that using unsigned int instead of int can speed up the code. Is this true? If so, why? Are there are any other rules one should follow to optimize the code for speed (i.e....
19
by: llothar | last post by:
I must say i didn't expect this. I just did some measures on FreeBSD 6.2 with gcc 3.4.6 and there is absolutely no significant difference between 32 and 64 bit mode - neither in compilation speed,...
13
by: Ciaran | last post by:
Hi All, Is it faster to have mySql look up as much data as possible in one complex query or to have php do all the complex processing and submit lots of simple queries to the mysql database? ...
47
by: Mike Williams | last post by:
I'm trying to decide whether or not I need to move to a different development tool and I'm told that VB6 code, when well written, can be ten times faster than vb.net, but that if its badly written...
17
by: Suresh Pillai | last post by:
I am performing simulations on networks (graphs). I have a question on speed of execution (assuming very ample memory for now). I simplify the details of my simulation below, as the question I...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.