set_time_limit() not working...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

set_time_limit() not working...

Post by Deseree »

Sup guys, I have a script that should run for 1 hour maximum or less if the for loop finishes faster... but it's not ending, the processes never stops, always shows up until my server/computer crashes from too may processing being ran.....

Code: Select all

set_time_limit(3600);
ignore_user_abort();
this is at the ABSOLUTE TOP of the script.... should I put it in the for loop, because i have not tried that ....

Why does the script hang or just run for days if i have those set.... is there any way i can prevent it from running more than 60 minutes?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I don't think you need the ignore line... although that does depend on your other code a bit.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Make sure the server is ALLOWING you to set the timeout. If your server is running with SAFE_MODE enabled then you cannot change the script timeout using set_time_limit. It will be completely ignored and no error will be given. Then it relies on the max_execution_time set in the php.ini. Also, if you are performing any system calls inside a php script and it is getting locked into a loop inside a system call then you are out of luck because the max_execution_time and set_time_limit do not affect system calls.
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

AKA Panama Jack wrote:Make sure the server is ALLOWING you to set the timeout. If your server is running with SAFE_MODE enabled then you cannot change the script timeout using set_time_limit. It will be completely ignored and no error will be given. Then it relies on the max_execution_time set in the php.ini. Also, if you are performing any system calls inside a php script and it is getting locked into a loop inside a system call then you are out of luck because the max_execution_time and set_time_limit do not affect system calls.
safe mode is off, max_executtion_time is 30 . set_time_limit is not disabled in php, infact nothing is atm.

no system, or exec calls on my script, simple file() and file_get_contents() and a little bit of curl in some places.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Then you should probably put output statements in various locations inside the loop followed by a flush function.

Code: Select all

echo "Starting Loop number: " . $loopnumber . "<br>";
flush();

...

echo "Executing query " . $query . "<br>";
flush();

...


echo "End of loop<br>";
flush();
By using the flush command after each echo you are forcing PHP to flush its output buffers. You should then be able to see approximately WHERE in your loop the program is stopping. I wouldn't surprise me if it is halting on a CURL execution.


If you are running a windows server this will not do anything unfortunately.
Deseree
Forum Commoner
Posts: 84
Joined: Mon Feb 13, 2006 11:35 pm

Post by Deseree »

AKA Panama Jack wrote:Then you should probably put output statements in various locations inside the loop followed by a flush function.

Code: Select all

echo "Starting Loop number: " . $loopnumber . "<br>";
flush();

...

echo "Executing query " . $query . "<br>";
flush();

...


echo "End of loop<br>";
flush();
By using the flush command after each echo you are forcing PHP to flush its output buffers. You should then be able to see approximately WHERE in your loop the program is stopping. I wouldn't surprise me if it is halting on a CURL execution.


If you are running a windows server this will not do anything unfortunately.
lol, yes this is what i call debugging and i've done this already, just i run everything hidden on my windows pc ( via windows cron ) and i run things using cron on the server.....

sometimes i try running things via screen and watch the progress, sometimes it finishes, sometimes it doesn't and just gets stuck, i don't know exactly where inside the loop since all my outputting is outside the loop, but i guess i'll put somemore inside and figure out.
Post Reply