Check running scripts

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Check running scripts

Post by John Cartwright »

I have a script that will be run for about 5 hours, now I have set_time_limit(0) so I want to let it finsih, although even if I click the STOP button in my browser the script still seems to run. Anyone know how to prevent the script from continuing -- this is extremely annoiying :evil:

My next question, is there any way to interact with php to determine which scripts are being run in any way? Yes Im praying for some magical technique.. :(
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I've noticed this problem too. Every once in a while, my complex parser scripts will hit a bug and go into infinite loops. I try a fix, refresh, and then try again. But since the default max execution time is 30 seconds, I easily go up to 8 processes, cumulatively using up all of my CPU (and necessating the manual killing of the processes)

I'd say use command line.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Or have the script served by the webserver start a command line script and then track progress by the process ID (saved in the session).
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Thanks for the comments guys.
arborint wrote:Or have the script served by the webserver start a command line script and then track progress by the process ID (saved in the session).
Can you elaborate a bit on this please?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

You'd probably need to use proc_open() and check with proc_get_status(). But as I recall when I did it a while back without those functions I got the process running and saved the PID in the session. The I could check if that PID was still running as necessary and report whether it was done or not. There was the usual monkeying around to get it to work as I recall.
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Thanks again Aborint.
Post Reply