maliary Posted June 25, 2009 Share Posted June 25, 2009 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++; } Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/ Share on other sites More sharing options...
n1tr0b Posted June 25, 2009 Share Posted June 25, 2009 the script you called took it more than 30 seconds to respond therefore.. returning an error Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-863271 Share on other sites More sharing options...
dzelenika Posted June 25, 2009 Share Posted June 25, 2009 put while($test_request==$requests->FetchRow()) instead of while($test_request=$requests->FetchRow()) Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-863287 Share on other sites More sharing options...
maliary Posted June 27, 2009 Author Share Posted June 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-864691 Share on other sites More sharing options...
dzelenika Posted June 28, 2009 Share Posted June 28, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-865010 Share on other sites More sharing options...
maliary Posted June 29, 2009 Author Share Posted June 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-865487 Share on other sites More sharing options...
Dathremar Posted June 29, 2009 Share Posted June 29, 2009 If You are sure that the script just needs more time to execute use: set_time_limit() function Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-865492 Share on other sites More sharing options...
iSE Posted June 29, 2009 Share Posted June 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-865494 Share on other sites More sharing options...
dzelenika Posted June 29, 2009 Share Posted June 29, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/163602-fatal-error-maximum-execution-time-of-30-seconds-exceeded/#findComment-865496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.