I have a cronjob that runs a PHP file that runs a DAEMON written in PHP, but I only want to run the DAEMON if no other instances of it are running, how can I get a list of P
To get the list of PHP processes see this question:
How to get list of running php scripts using PHP exec()?
Another option is that you can acquire a lock of the file and then check it before running: for example:
$thisfilepath = $_SERVER['SCRIPT_FILENAME'];
$thisfilepath = fopen($thisfilepath,'r');
if (!flock($thisfilepath,LOCK_EX | LOCK_NB))
{
customlogfunctionandemail("File is Locked");
exit();
}
elseif(flock($thisfilepath,LOCK_EX | LOCK_NB)) // Acquire Lock
{
// Write your code
// Unlock before finish
flock($thisfilepath,LOCK_UN); // Unlock the file and Exit
customlogfunctionandemail("Process completed. File is unlocked");
exit();
}
Basically in the above example you are first checking if the file is locked or not and if it is not locked (means process is completed) you can acquire lock and begin your code.
Thanks