Initial Commit
This commit is contained in:
48
dependencies/amphp/process/lib/Internal/Posix/Handle.php
vendored
Normal file
48
dependencies/amphp/process/lib/Internal/Posix/Handle.php
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace WP_Ultimo\Dependencies\Amp\Process\Internal\Posix;
|
||||
|
||||
use WP_Ultimo\Dependencies\Amp\Deferred;
|
||||
use WP_Ultimo\Dependencies\Amp\Loop;
|
||||
use WP_Ultimo\Dependencies\Amp\Process\Internal\ProcessHandle;
|
||||
/** @internal */
|
||||
final class Handle extends ProcessHandle
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->pidDeferred = new Deferred();
|
||||
$this->joinDeferred = new Deferred();
|
||||
$this->originalParentPid = \getmypid();
|
||||
}
|
||||
/** @var Deferred */
|
||||
public $joinDeferred;
|
||||
/** @var resource */
|
||||
public $proc;
|
||||
/** @var resource */
|
||||
public $extraDataPipe;
|
||||
/** @var string */
|
||||
public $extraDataPipeWatcher;
|
||||
/** @var string */
|
||||
public $extraDataPipeStartWatcher;
|
||||
/** @var int */
|
||||
public $originalParentPid;
|
||||
/** @var int */
|
||||
public $shellPid;
|
||||
public function wait()
|
||||
{
|
||||
if ($this->shellPid === 0) {
|
||||
return;
|
||||
}
|
||||
$pid = $this->shellPid;
|
||||
$this->shellPid = 0;
|
||||
Loop::unreference(Loop::repeat(100, static function (string $watcherId) use($pid) {
|
||||
if (!\extension_loaded('pcntl') || \pcntl_waitpid($pid, $status, \WNOHANG) !== 0) {
|
||||
Loop::cancel($watcherId);
|
||||
}
|
||||
}));
|
||||
}
|
||||
public function __destruct()
|
||||
{
|
||||
$this->wait();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user