473,395 Members | 1,581 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,395 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 2921
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.