php-censor/PHPCI/ProcessControl/PosixProcessControl.php
Adirelle 7de9023810 Reworked the DaemonCommand.
* Accepts options for PID and log file.
* Uses posix_kill whenever available.
* Checks that the daemon actually started or stopped.
* Try to terminate then kill the daemon.
* Uses the logger or output instead of "echo".

Added a ProcessControl interface and implementations.

Closed #908
2015-05-28 10:55:59 +02:00

53 lines
1.2 KiB
PHP

<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2015, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link https://www.phptesting.org/
*/
namespace PHPCI\ProcessControl;
/**
* Control process using the POSIX extension.
*
* @author Adirelle <adirelle@gmail.com>
*/
class PosixProcessControl implements ProcessControlInterface
{
/**
*
* @param int $pid
* @return bool
*/
public function isRunning($pid)
{
// Signal "0" is not sent to the process, but posix_kill checks the process anyway;
return posix_kill($pid, 0);
}
/**
* Sends a TERMINATE or KILL signal to the process using posix_kill.
*
* @param int $pid
* @param bool $forcefully Whetehr to send TERMINATE (false) or KILL (true).
*/
public function kill($pid, $forcefully = false)
{
posix_kill($pid, $forcefully ? 9 : 15);
}
/**
* Check whether this posix_kill is available.
*
* @return bool
*
* @internal
*/
public static function isAvailable()
{
return function_exists('posix_kill');
}
}