Jump to content

Recommended Posts

Hello,

 

I am getting the error Fatal error: Maximum execution time of 30 seconds exceeded in <url to the php page> line 334 . This error is on and off. Nothing wrong with the code as seen below, the red part is the line in question, that the error points to .

 

I change the max time limit in php.ini and set it to 45. This is not the best solution for this I know,but my question is : Do server delays result in this kind of error we are having here ?

 

$flag=null;
$y=0;
while($test_request=$requests->FetchRow())
{
    $flag[$y] = false;
    //check if numbers have been already printed
    $len=count ($printed_nrs);

    for ($x=0;$x<$len;$x++)
    {
     [b]Line 449 is here :-[/b]  if (strcmp ($test_request['batch_nr'],$printed_nrs[$x]) == 0 )
        {
            $flag[$y]=true;
            $flag[$x]=true;  
        }
   }   
   $printed_nrs[$x]=$test_request['batch_nr'];
   $y++;
}

 

Not too sure about that,

 

the = operator is an assingment operator hence int x = 2 implies int x has a value of 2.

 

the == operator equates variables hence int x == int y means the two are equal.

 

Am not trying to equate but to assign the returned results to  $test_request.

 

Not too sure about that,

 

the = operator is an assingment operator hence int x = 2 implies int x has a value of 2.

 

the == operator equates variables hence int x == int y means the two are equal.

 

Am not trying to equate but to assign the returned results to  $test_request.

OK, I understand.

 

What is the number of fetched rows and $test_request['batch_nr']?

Have You measured spent time by by parts of Your loop to see where are You loosing the most time?

I normally put the line set_time_limit(30); inside the loop, so that on each iteration, the timer resets and it gets another 30 seconds to complete. If you want to benchmark how long the different parts of your script take, use the following:

 

$timeStart = microtime(true);
echo 'The time at the start of the script is: +' . (microtime(true) - $timeStart);

$flag=null;
$y=0;

while($test_request=$requests->FetchRow())
{
echo 'Start "while" loop at: +' . (microtime(true) - $timeStart);
    $flag[$y] = false;
    //check if numbers have been already printed
    $len=count ($printed_nrs);

    for ($x=0;$x<$len;$x++)
    {
    echo 'Start "for" loop at: +' . (microtime(true) - $timeStart);
     [b]Line 449 is here :-[/b]  if (strcmp ($test_request['batch_nr'],$printed_nrs[$x]) == 0 )
        {
            $flag[$y]=true;
            $flag[$x]=true; 
        }
    echo 'Finish "for" loop at: +' . (microtime(true) - $timeStart);
   }   
   $printed_nrs[$x]=$test_request['batch_nr'];
   $y++;
echo 'Finish "while" loop at: +' . (microtime(true) - $timeStart);
}
echo 'The time at the end of the script is: +' . (microtime(true) - $timeStart);

 

Or move the lines to where you think they would be better showing you the execution time.

 

Intresting dzelenika,

but how would I measure the time spent by the diffrent parts of the loop ?

 

Al get back to you on the number of rows.

 

try something like this

$flag=null;
$y=0;

while($test_request=$requests->FetchRow())
{  $ref_time = microtime(true);
    $flag[$y] = false;
    //check if numbers have been already printed
    $len=count ($printed_nrs);
$pass_time1 += microtime(true)+ $ref_time;
    for ($x=0;$x<$len;$x++)
    {
     [b]Line 449 is here :-[/b]  if (strcmp ($test_request['batch_nr'],$printed_nrs[$x]) == 0 )
        {
            $flag[$y]=true;
            $flag[$x]=true; 
        }
   }   
$pass_time2 += microtime(true)+ $ref_time;
   $printed_nrs[$x]=$test_request['batch_nr'];
   $y++;
$pass_time3 += microtime(true)+ $ref_time;
}
echo $pass_time1 ... $pass_time2 ... $pass_time3 ...

if (as I'm expecting) most of time is spent in for loop then go probe the same in for loop and so on until you find most time consuming code part

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.