2022-05-30 17:10:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
class DaemonHelpers
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* https://stackoverflow.com/a/3111757
|
|
|
|
*
|
|
|
|
* Checks if process with pid in $pidFile is still running
|
|
|
|
*
|
|
|
|
* @param $pidFile
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function isProcessRunning($pidFile = '/var/run/myfile.pid') {
|
|
|
|
if (!file_exists($pidFile) || !is_file($pidFile)) return false;
|
2022-09-21 16:33:29 +02:00
|
|
|
$lasttick = file_get_contents($pidFile);
|
|
|
|
$return = ((int)$lasttick >= (time() - 30));
|
2022-05-30 17:10:32 +02:00
|
|
|
if (!$return) unlink($pidFile);
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|