Re: PHP slowness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there, just for testings sake, you should get a script that figures out the page generation time for a php script... As luck would have it, I made a class for this not too long ago. give this a whirl.

First, create a php script with this in it...
<?php
// CREATE THE CLASS
class page_gen {
// CLASS VARIABLES
var $start_time;
var $end_time;
var $gen_time;
// USER DEFINE VARIABLES
var $color_good;
var $color_fair;
var $color_poor;
// FIGURE OUT THE TIME AT THE BEGINNING OF THE PAGE
function start() {
$this->start_time = microtime();
}
// FIGURE OUT THE TIME AT THE END OF THE PAGE
function stop() {
$this->end_time = microtime();
}
// CALCULATE THE DIFFERENCE BETWEEN THE BEGINNNG AND THE END AND COLOR CODE THE RESULT
function gen() {
$this->gen_time = $this->end_time - $this->start_time;
if (!isset($this->color_good)) {
$this->color_good = "green";
}
if (!isset($this->color_fair)) {
$this->color_fair = "yellow";
}
if (!isset($this->color_poor)) {
$this->color_poor = "red";
}
if ($this->gen_time <= 0.0999999999) {
$this->gen_time = "<span style=\"color: $this->color_good;\">$this->gen_time</span>";
} elseif ($this->gen_time <= 0.999999999 && $this->gen_time > 0.0999999999) {
$this->gen_time = "<span style=\"color: $this->color_fair;\">$this->gen_time</span>";
} elseif ($this->gen_time <= 9.99999999 && $this->gen_time > 0.999999999) {
$this->gen_time = "<span style=\"color: $this->color_poor;\">$this->gen_time</span>";
}
print("<span style=\"font-weight: bold;\">$this->gen_time</span> seconds");
}
}
?>


Now, put this code at the top of the page you want to time.

<?php
   require("cls.pagegen.php");   // or whatever you named it
   $gentime = new page_gen();
   $gentime->start();
?>

Where you want to stop timing (usually at the bottom).

<?php
   $gentime->stop();
?>

Now to display the time, simply go

<?php
   $gentime->gen();
?>

It will color code it for you and everything, give it a whirl and let us know what it tells you.

Gerard wrote:

Hello people,

Recently, one of my webservers became rather slow. At first we thought it
was the MySQL backend, but when logged in on MySQL using the command line
tool over SSH, it runs as smooth as ever.
Static content (normal html pages) also load without delay. It seems that
the bottleneck is PHP itself.
For the sake of comparison, I created 2 test pages:

http://www.debuginc.com/test.html
http://www.debuginc.com/test.php

Everyone I asked says that the PHP page takes over 5 seconds to load while
the HTML one instantly displays. The only code in the PHP page is <? echo
'hello world'; ?>. No MySQL stuff, so that eliminates the initial idea of
MySQL causing the slowness.

Nevertheless, it IS slow and I have no idea why or where to start looking.
The phpinfo() can be found on www.debuginc.com/info.php. Any help or hints
are highly appreciated.

Another interesting note; this problem started a couple of days ago without
any changes in the config or anything. At first I upped the amount of
connections Apache would accept, but it soon turned out that was not the
problem.

Thanks,
- Gerard




-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux