Google Answers Logo
View Question
Q: PHP problem: slow ECHO command. ( No Answer,   0 Comments )
Subject: PHP problem: slow ECHO command.
Category: Computers > Operating Systems
Asked by: fmaz-ga
List Price: $50.00
Posted: 22 May 2006 16:22 PDT
Expires: 26 May 2006 11:07 PDT
Question ID: 731456
I've an ECHO command that sometime take over 300 second to be done in
PHP 5. The line is:

echo $he_buffer;

And the $he_buffer contain a 250Kb text.
My site is hosted on a VPS server under Cent OS. I use Apache 1, PHP 5
and MySQL 4.1.18 But I've timed all the mysql query and they are all

Note that the problem is random. Most of the time (99%) the page are
generated under a second. But sometime it take A BIG AMOUNT OF TIME.

As PHP doesn't timeout, it mean that the CPU is not fully used
(because their is a 30 second timeout based on the CPU USAGE)

It can seem like a programming question, but I'm pretty sure that my
command is ok so I guess it's more a system configuration problem.

I need to solve this problem.

Request for Question Clarification by webadept-ga on 22 May 2006 17:12 PDT

The problem is probably much more involved than echoing a variable,
and is most likely tied to the code previously run, for example when
the queries are run and how often, .. how many did it take to build
this variable value..

Basically what I'm suggesting here is that you aren't giving us enough
to help you with this.

You might want to take a look at this page and get some ideas of what
could be happening ...

This page also has some good hints

After reading those, if you feel that I might still be able to help
you, we can get started, but I'll need more of a block of your code
than just the echo command and some idea of what creates that variable
value... and where.


Clarification of Question by fmaz-ga on 22 May 2006 17:52 PDT
I've placed a timer on each query.

I've also placed a timer on the while loop that generate the $he_buffer variable

Here is a little more technical details about the code (I guess I must
prove AGAIN that the code is not in fault..)

The timer function:
class timer
	function start(){
		global $starttime;
		$time = microtime();
		$time = explode( ' ', $time );
		$time = $time[0] + $time[1];
		$starttime = $time;
	function finish(){
		global $starttime;
		$time = microtime();
		$time = explode( ' ', $time );
		$time = $time[0] + $time[1];
		$finishtime = $time;
		$totaltime = round( ( $finishtime - $starttime ), 4 );
		return $totaltime;
$timer = new timer;

The way I calculate the time that a mysql query use and add it to the report:
	$avant = $timer->finish();
	$ret = mysql_query($db_string);
	$apres = $timer->finish();
	if ($ret === false) {
		ErrorDB($db_string, $file, $line);
	$query_mail_report.="Avant: $avant Après: $apres Temps: " .
($apres-$avant) . "\n";
	$query_mail_report.=$db_string . "\n";

The way I do calculate the time that the echo command take:
//Affichage du buffer qui contiend tout les messages (250kb)
$avant = $timer->finish();
echo $he_buffer;
$apres = $timer->finish();

//Calcul du temps qu'à pris le buffer à s'afficher
$query_mail_report.= "\nECHO DU HE: Début @:" . $avant . " Fin @" .
$apres . "Durée: " . ($apres-$avant) . "\n";

And more than that: the problem is not alway there and this is not a
mysql caching problem:

- You display it once: 0.6 sec to generate
- You refresh it: 0.5 sec to generate
- You refresh it again: 454 sec to generate
- You refresh it again: 0.7 sec to generate


More than that:
I was on a shared hosting before and the site was running correctly
(and for over a year!)
Now I've moved to a VPS server, and I have this problem. I've not
changed the code...

Request for Question Clarification by webadept-ga on 22 May 2006 18:42 PDT
Hi again, 

Well you haven't posted any of the code here, you've just showed me
your timer, so I can't make any tests. It appears that you want me to
verify that the VPS server is at fault, and I can't do that without at
least some hint as to what is going on. I believe you... but I still
can't verify or try to give you a solution. So I'm going to bow out of
this one and let some other researcher take over.



Clarification of Question by fmaz-ga on 22 May 2006 19:08 PDT
Well, I will not post the full code here because it inside a too
complex application. The whole application require over 10 pages and
for building the variable that slow down the echo, their is a query
using 4 or 5 mysql tables (yes, I've timed the query under PHPMyAdmin
and with my timer, everything is ok)

So if you need further informations, I can't give them in public (it
would be too much data), but just contact me in private and I'll give
you more information about all you need to know to solve my problem.

you can contact me at: mj[àt]cybercity2034[d0t]com

Clarification of Question by fmaz-ga on 22 May 2006 19:15 PDT
And I even if I give you the whole code, you could not reproduce the
problem because:

- it appear randomly
- you will not be able to generate the $he_buffer content as is use a
450mb database ... that you don't want me to copy&pastle here
- you don't have the users that connect and ask for differents pages
at the same time (if you do a stress test, the server will just use
the cache and the test will not be valid)

It's not that I don't want to, it's simply that I can't post all that
you would need to reproduce the testing environnement in this little

And again: How do you explain that the timers are returning thoses
values ONLY for the 'echo line' ? If it was a MySQL problem, why the
timers are always displaying big number at this specific line and not
on the mysql query ?

Clarification of Question by fmaz-ga on 22 May 2006 19:46 PDT
Ho, also, the forum (SMF 1.0.5) also do the same thing... but it's
less critical. The generation time can sometime go upto 45 seconds and
sometime the page is simply all blank (nothing is sent to the
browser). But the blank page is probably another problem that is less

Also, both problem (but don't investigate about the blank page one
except if it's the same problem as the first one) have been confirmed
by members from Canada, Belgium and France.

Ps.: I'm not the conceptor of SMF... So same problem, on two different
part of the site using different table and created by totally
different persons.
There is no answer at this time.

There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy