php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35054 Heavy "Random" Lag During foreach loop
Submitted: 2005-11-01 18:41 UTC Modified: 2005-11-01 23:13 UTC
From: starcitsura at shaw dot ca Assigned:
Status: Closed Package: Performance problem
PHP Version: 4.4.1RC1 OS: Linux
Private report: No CVE-ID: None
 [2005-11-01 18:41 UTC] starcitsura at shaw dot ca
Description:
------------
For some reason there is random lag when echoing the results.
Now I say random lightly because there seems to be a tendency for certain items to be more likely to slow down then others, for instance at one point I ran the script about 10 times, and item six in the list always slowed down.

The lag seemed to occur inside the part that echoed each image and link, at that time the lag would only occur on the image for the down button which makes even less sense.
I used a micro time function that would echo the time since the last one was called. The lag seemed to occur during the html portion of the code., which doesn?t make much sense to me.

What is causing this lag? I have also written the code so that it echo?s the html instead of the way its done now, there was no effect on the lag

I wouldn't be worried about it if it was only like 15 milliseconds difference, but the lag varies anywhere from 100 ms to 1500ms which is not acceptable. Some time?s the list is as long as 100 items, in which case the items with lag are much more common, causing the script to take as long a 10000ms.

I have tested this script on two different servers, the lag occurs on both.
The main server uses PHP 4.3.11


Reproduce code:
---------------
foreach($array as $value)
{
  $conID = substr($value, 1);
  switch ($value{0})
  {   #simply choses which mysql query to run, then runs it  }
  list($name,$built) = $data;
  $data = new entity($name);
  $cost = $data->fetchField('Cost'); ?>
<li><?=$name;?> (<?=($cost-$built);?>/<?=$cost;?>)
<a href="?LID=<?=$LID;?>&amp;conID=<?=$value{0}.$conID;?>&amp;shift=up" title="Up">
<img alt="Up" src="../../images/ingame/map/up.gif" height="11" width="11" /></a>
<a href="?LID=<?=$LID;?>&amp;conID=<?=$value{0}.$conID;?>&amp;shift=x" title="Cancel">
<img alt="Cancel" src="../../images/ingame/map/x.gif" height="11" width="11" /></a>
</li>
<?php
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-01 22:26 UTC] sniper@php.net
Are you sure it's not Apache or Mysql lagging? Where do you get the idea it's automatically PHP's fault? Can you provide a script which can be run in CLI and which does NOT use mysql?
(and which is actually complete script and not just useless piece of a huge one)

 [2005-11-01 23:13 UTC] starcitsura at shaw dot ca
nevermind then
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC