public function setPidFile($pidFile)
    {
        $dir = realpath(dirname($pidFile));
        $filename = basename($pidFile);

        if (substr($pidFile, -1) == '/' or $filename == '.') {
            throw new \InvalidArgumentException('The pid file "'.$pidFile.'" must be a valid file path');
        }

        if (!is_dir($dir)) {
            throw new \RuntimeException('The pid file directory "'.$dir.'" does not exist');
        }

        if (!is_writeable($dir)) {
            throw new \RuntimeException('The pid file directory "'.$dir.'" is not writeable');
        }

        $this->pidFile = $dir.'/'.$filename;

        if (file_exists($this->pidFile) and posix_kill((int)trim(file_get_contents($this->pidFile)), 0)) {
            throw new \RuntimeException('Pid file "'.$pidFile.'" already exists and worker is still running.');
        }

        if (!file_put_contents($this->pidFile, getmypid(), LOCK_EX)) {
            throw new \RuntimeException('Could not write pid to file "'.$pidFile.'"');
        }
    }
public function setPidFile($pidFile)
    {
        $dir = realpath(dirname($pidFile));
        $filename = basename($pidFile);

        if (substr($pidFile, -1) == '/' or $filename == '.') {
            throw new \InvalidArgumentException('The pid file "'.$pidFile.'" must be a valid file path');
        }

        if (!is_dir($dir)) {
            throw new \RuntimeException('The pid file directory "'.$dir.'" does not exist');
        }

        if (!is_writeable($dir)) {
            throw new \RuntimeException('The pid file directory "'.$dir.'" is not writeable');
        }

        $this->pidFile = $dir.'/'.$filename;

        if (file_exists($this->pidFile) and posix_kill((int)trim(file_get_contents($this->pidFile)), 0)) {
            throw new \RuntimeException('Pid file "'.$pidFile.'" already exists and worker is still running.');
        }

        if (!file_put_contents($this->pidFile, getmypid(), LOCK_EX)) {
            throw new \RuntimeException('Could not write pid to file "'.$pidFile.'"');
        }
    }
public function setPidFile ( $ pidFile ) { $ dir = realpath ( dirname ( $ pidFile ) ) ; $ filename = basename ( $ pidFile ) ; if ( substr ( $ pidFile , - 1 ) == '/' or $ filename == '.' ) { throw new \ InvalidArgumentException ( 'The pid file "' . $ pidFile . '" must be a valid file path' ) ; } if ( ! is_dir ( $ dir ) ) { throw new \ RuntimeException ( 'The pid file directory "' . $ dir . '" does not exist' ) ; } if ( ! is_writeable ( $ dir ) ) { throw new \ RuntimeException ( 'The pid file directory "' . $ dir . '" is not writeable' ) ; } $ this -> pidFile = $ dir . '/' . $ filename ; if ( file_exists ( $ this -> pidFile ) and posix_kill ( ( int ) trim ( file_get_contents ( $ this -> pidFile ) ) , 0 ) ) { throw new \ RuntimeException ( 'Pid file "' . $ pidFile . '" already exists and worker is still running.' ) ; } if ( ! file_put_contents ( $ this -> pidFile , getmypid ( ) , LOCK_EX ) ) { throw new \ RuntimeException ( 'Could not write pid to file "' . $ pidFile . '"' ) ; } }
Set the worker pid file

@param  string     $pidFile Filename to store pid in
@throws \Exception
Set the worker pid file