Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a php script is still running

I have a script that listens to a jabber server and responds accordingly. Though it's not supposed to stop, last night it did. Now I want to run a cron job every minute to check if the script is running, and start it if not.

The question is, how do I check if a particular script is still running?

Some solutions have been posted here, but those are all for Linux, while I am looking for a Windows solution. Any ideas please? Thanks.

like image 987
Nirmal Avatar asked Apr 14 '10 01:04

Nirmal


People also ask

How do I know if a PHP script is running?

Check if a PHP script is already running If you have long running batch processes with PHP that are run by cron and you want to ensure there's only ever one running copy of the script, you can use the functions getmypid() and posix_kill() to check to see if you already have a copy of the process running.

How do I know if PHP script is running on Linux?

Replace #user# with your script user. Show activity on this post. The above code lists all php processes running in full, then checks to see if "my_script. php" is in the list of running processes, if not it runs the process and does not wait for the process to terminate to carry on doing what it was doing.

How do I stop a PHP script from running?

The exit() function in PHP is an inbuilt function which is used to output a message and terminate the current script. The exit() function only terminates the execution of the script.

Can a PHP script run forever?

You can make it run forever by either setting the value or call set_time_limit in your script (http://php.net/manual/en/function.set-time-limit.php).


1 Answers

A quick and dirty workaround could be for the script to update a row in a database with a date column set to CURRENT_TIMESTAMP. Have the cron second script check if the timestamp of this row is recent.

like image 181
Danten Avatar answered Oct 03 '22 17:10

Danten