public static function kill($file, $delete = false)
    {
        if (!extension_loaded('posix')) {
            throw new \Exception('posix extension required');
        }

        if (!is_readable($file)) {
            throw new \Exception('unreadable pid file ' . $file);
        }

        if (($lock = @fopen($file, 'c+')) === false) {
            throw new \Exception('unable to open pid file ' . $file);
        }

        if (flock($lock, LOCK_EX | LOCK_NB)) {
            flock($lock, LOCK_UN);
            throw new \Exception('process not running');
        }

        $pid = fgets($lock);
         
        if (posix_kill($pid, SIGTERM)) {
            if ($delete) unlink($file);
            return true;
        } else {
            return false;
        }
    }
public static function kill($file, $delete = false)
    {
        if (!extension_loaded('posix')) {
            throw new \Exception('posix extension required');
        }

        if (!is_readable($file)) {
            throw new \Exception('unreadable pid file ' . $file);
        }

        if (($lock = @fopen($file, 'c+')) === false) {
            throw new \Exception('unable to open pid file ' . $file);
        }

        if (flock($lock, LOCK_EX | LOCK_NB)) {
            flock($lock, LOCK_UN);
            throw new \Exception('process not running');
        }

        $pid = fgets($lock);
         
        if (posix_kill($pid, SIGTERM)) {
            if ($delete) unlink($file);
            return true;
        } else {
            return false;
        }
    }
public static function kill ( $ file , $ delete = false ) { if ( ! extension_loaded ( 'posix' ) ) { throw new \ Exception ( 'posix extension required' ) ; } if ( ! is_readable ( $ file ) ) { throw new \ Exception ( 'unreadable pid file ' . $ file ) ; } if ( ( $ lock = @ fopen ( $ file , 'c+' ) ) === false ) { throw new \ Exception ( 'unable to open pid file ' . $ file ) ; } if ( flock ( $ lock , LOCK_EX | LOCK_NB ) ) { flock ( $ lock , LOCK_UN ) ; throw new \ Exception ( 'process not running' ) ; } $ pid = fgets ( $ lock ) ; if ( posix_kill ( $ pid , SIGTERM ) ) { if ( $ delete ) unlink ( $ file ) ; return true ; } else { return false ; } }
Kills a daemon process specified by its PID file.

@throws \Exception

@param string $file   Daemon PID file
@param bool   $delete Flag to delete PID file after killing

@return bool True on success, false otherwise
Kills a daemon process specified by its PID file .