logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: PHP5 x10 slower than PHP4 (disk reads)?
Author
Brian



Joined: 21 Oct 2005
Posts: 209
Location: Puyallup, WA USA

PostPosted: Sun 25 Jun '06 22:54    Post subject: PHP5 x10 slower than PHP4 (disk reads)? Reply with quote

G'Day All,

I am migrating from PHP4 to PHP5, from a 1.3Ghz box to a 2.4Ghz box. I am very curious why when doing some speed tests that my scripts are indeed faster or as fast on PHP5 and the newer, faster box (faster cpu), but on disk reads, specifically recursive directory searches, it is about 10 times slower.

I have to wonder, is it the hardware? We are using the same brand / model of hard drives, all ATA100, all with proper IDE cables (not ATA33 cables). Let's see, I ran speed tests with a utility called HD Tune on both servers and considering the current server (PHP4 box) is under heavy load, it still performs basically on par with the unloaded box. It does not seem to be an issue of HD's, HD interface, cables ... as far as I can see.

Here is the script that I run on each box:

Code:
<?php

$dir = ( strlen( $_GET['dir'] > 5 ) ) ? $_GET['dir'] : 'F:/some/dir/here';

function get_dir_tree($dir, $wdir, $xl) {
   $handle=opendir($dir);
   while($file=readdir($handle))
         $retVal[] = $file;
   closedir($handle);
   foreach($retVal as $k => $v) {
         if($v != '.' && $v != '..') {
         $count ++ ;
             if(is_dir($dir.'/'.$v)) {
            global $dirs;
            $value=substr($dir.'/'.$v,$xl);
            echo $value . '<br>';
                 get_dir_tree($dir.'/'.$v, $wdir, $xl);
            $dirs ++;
             }
      }
   }
}

function get_microtime() {
   $mtime=microtime();
   $mtime=explode(' ',$mtime);
   $mtime=$mtime[1] + $mtime[0];
   $time_is=$mtime;
   return $time_is;
}

$dirs = 0;
$start_time = get_microtime();
get_dir_tree( $dir, '/', 0);
$end_time = get_microtime();

echo '<hr>' . $dirs . ' located.<br>Time:  ' . ( $end_time - $start_time ) . '<hr>';
?>


$xl trims the display, $dir is the basedir, and $wdir is the sub if any to be selected for the test script.

So, I run this on my 1.3GHz underload and I can get results ranging from .6 seconds to about 2 seconds, completley dependent upon the load on the server at the time of the request.

On the newer, faster, PHP5 equiped box, I am seeing most often results of 4.1 to 4.6 seconds, regardless of if the script is cached. In some cases it took about 10 seconds, so I estimate an average of about 10 times longer for script execution.

Since the HD / ATA controllers are same speed, and since I am using proper cables, since the new box is using PHP5 and not under any load, why would this script take about 10 times longer on average, and about 6 times faster at best?

Any thoughts?

Could it be a MB issue with the IDE controller?

Just not sure what to look for here?


I am running Apache 2.0.54 on old box Windows XP stripped down to about 22 processes. On new box I am running Apache 2.2.2 also XP Pro stripped down to about 22 processes. Both machines run lean and are configured to favor services and caching over application execution (better for servers)

Again, thanks for your thoughts.

--
Brian
Back to top
Brian



Joined: 21 Oct 2005
Posts: 209
Location: Puyallup, WA USA

PostPosted: Mon 26 Jun '06 0:40    Post subject: Reply with quote

Just a follow up, and it is a bit frustrating to say the least.

I installed and launched Apache 2.2.2 (Land10 Build) with PHP 4.4.2, connected with Land10 (Steffens) DLL's. The speed difference with the above posted script was absolutely amazing!!!

In one instance I configured the script to read my Windows directory for the test ... this machine is development stages so it is safe to allow this level of basedir.

It took PHP5 with this script 41 seconds to scan and display the c:/windows dir but in PHP4 it took slightly under 3 seconds from a dead stop to completion. I repeated the test in PHP 5, it sucks big time!

I found that PHP5 is plenty fast on all other operations, but the way it is reading the drives, well I just cannot understand why the deal is. Perhaps it is a config snafu, but realistically, it would be safe to say that is not it.

Here is the rub, I would love to use PHP5, but PHP4.4.2 on this box would due. I cannot get PHP4.4.2 to connect to MySQL5 .... what the hell, this is very strange to say the least.

Anyone else having similar problems?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7288
Location: Germany, Next to Hamburg

PostPosted: Mon 26 Jun '06 9:54    Post subject: Reply with quote

PHP 5 runs well.
C:/Windows

433 located.
Time: 3.6724438667297

Did you use the same ini settings?

Sorry I do not have PHP 4 for testing.
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3049
Location: Hilversum, NL, EU

PostPosted: Mon 26 Jun '06 15:03    Post subject: Reply with quote

My question is also same php.ini ?

Here on Win XP2 with php 5.1.4 and Apache 2.2.2:

412 located.
Time: 5.0295331478119

My hardware:
CPU Type Intel Pentium 4, 2800 MHz, Socket 478, Chipset i875P
Memory 2GB(PC3200 ECC DDR SDRAM), Dual
Disk Drive 2X Seagate ST340014A (40 GB, 7200 RPM, Ultra-ATA/100)


I heard more that in some area's php5 is slower then php4, but I cannot recall soo much diff as yours.

Maybe you can run sandra benchmarks for your drive and memory, just to see if they are on par with the reference drives/memory.

Steffen
Back to top
Jorge



Joined: 12 Mar 2006
Posts: 376
Location: Belgium

PostPosted: Mon 26 Jun '06 16:06    Post subject: Reply with quote

Steffen wrote:
My question is also same php.ini ?

Here on Win XP2 with php 5.1.4 and Apache 2.2.2:

412 located.
Time: 5.0295331478119

My hardware:
CPU Type Intel Pentium 4, 2800 MHz, Socket 478, Chipset i875P
Memory 2GB(PC3200 ECC DDR SDRAM), Dual
Disk Drive 2X Seagate ST340014A (40 GB, 7200 RPM, Ultra-ATA/100)


I heard more that in some area's php5 is slower then php4, but I cannot recall soo much diff as yours.

Maybe you can run sandra benchmarks for your drive and memory, just to see if they are on par with the reference drives/memory.

Steffen


I for one have noticed that the file() command is slower... then again get_file_content() is lightning fast!
Back to top
Brian



Joined: 21 Oct 2005
Posts: 209
Location: Puyallup, WA USA

PostPosted: Tue 27 Jun '06 14:57    Post subject: Reply with quote

I built a new php.ini file, and having gone through it with a fine tooth comb, I don't believe that there is anyting in it that I could alter to make things better. Truly, there are only a few differences between 4.x and 5.x in the INI file that I could see, but as I stated I used a clean from scratch install.

Yes, reading files, reading the contents of a directory and most operations were just super fast in PHP 5, but darn if reading a directory tree isn't painfully slow. It is not only slow, but it is massively CPU intensive - to a point where if three or four were trying to login at the same time, and if a CGI script were executing that I suspect it would crash the server.

I tried with and without APC, I tried with various settings in terms of output buffering, caching, and there was simply no setting(s) that had any effect on PHP5's performance.

I have to wonder if Windows is getting left behind in the PHP5 world?

I may wipe out MySQL, wipe out PHP5, remove all traces of MySQL5 in fact and re-connect 4 to mysql 4 and move forward with old versions. It's frustrating because I do want to use the latest technologies, but I may be stuck with PHP4, MySQL4, Apache 2.0.x and that just may be the way it is. One nice thing about PHP5, the php_perl.dll extension ... haven't had a chance to use it, but it must be nice to wrap Perl scripts inside of PHP, so convenient!

Steffen wrote:
Here on Win XP2 with php 5.1.4 and Apache 2.2.2:

412 located.
Time: 5.0295331478119


...and...

James Blond wrote:
PHP 5 runs well.
C:/Windows

433 located.
Time: 3.6724438667297


If that was the initial scan, mmmmm, maybe it's sort of okay, but in PHP 4 I get times of about half that. I found that in some instances I was seeing 10 times faster results in PHP4. I suspect a PHP5 issue with caching ... or something to do with connections and how they are opened, closed, and maintianed. I think, and I am just guessing, that PHP4 has some sort of "connection cache" or something like that, and that PHP5 does not, or it needs to be enabled. I just don't know quite how to start looking for such a thing, what ever it may be ... LOL.

... about the php.ini file though,

Would you all mind terribly posting yours (scratch out the sensitive stuff), I'd love to compare notes if you don't mind, thanks

Thanks for your thoughts everyone, but so far no success with this due to the inability to recursively built a directory tree with all sub-directories being listed. No one at Devshed was able to help either.

--
Brian
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3049
Location: Hilversum, NL, EU

PostPosted: Tue 27 Jun '06 17:36    Post subject: Reply with quote

Yes, my initial scan.

You cannot stay for ever with php4.

You can give the latest snapshot a try at http://snaps.php.net/ . The dll for Apache2.2.2 is included in the .zip (called php5apache2_2.dll ), so no need to use the .dll from here.

If still worse, then I suggest you open a bug report for the php-guys at http://bugs.php.net/ .

Steffen
Back to top


Reply to topic   Topic: PHP5 x10 slower than PHP4 (disk reads)? View previous topic :: View next topic
Post new topic   Forum Index -> Other Software