eee
This commit is contained in:
@@ -30,6 +30,9 @@ class ProcessManager extends Component
|
|||||||
private array $_process = [];
|
private array $_process = [];
|
||||||
|
|
||||||
|
|
||||||
|
/** @var array<string, Process> $runner */
|
||||||
|
private array $runner = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -48,26 +51,17 @@ class ProcessManager extends Component
|
|||||||
{
|
{
|
||||||
$server = Kiri::getDi()->get(ServerInterface::class);
|
$server = Kiri::getDi()->get(ServerInterface::class);
|
||||||
foreach ($this->_process as $custom) {
|
foreach ($this->_process as $custom) {
|
||||||
$server->addProcess(new Process(function (Process $process) use ($custom) {
|
$this->runner[$custom->getName()] = new Process(function (Process $process) use ($custom) {
|
||||||
$this->extracted($custom, $process);
|
$this->extracted($custom, $process);
|
||||||
},
|
},
|
||||||
$custom->getRedirectStdinAndStdout(),
|
$custom->getRedirectStdinAndStdout(),
|
||||||
$custom->getPipeType(),
|
$custom->getPipeType(),
|
||||||
$custom->isEnableCoroutine()
|
$custom->isEnableCoroutine()
|
||||||
));
|
);
|
||||||
|
$server->addProcess($this->runner[$custom->getName()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Process[]
|
|
||||||
*/
|
|
||||||
public function getProcesses(): array
|
|
||||||
{
|
|
||||||
return $this->_process;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|OnProcessInterface|BaseProcess $custom
|
* @param string|OnProcessInterface|BaseProcess $custom
|
||||||
* @throws
|
* @throws
|
||||||
@@ -91,7 +85,7 @@ class ProcessManager extends Component
|
|||||||
*/
|
*/
|
||||||
public function shutdown(): void
|
public function shutdown(): void
|
||||||
{
|
{
|
||||||
foreach ($this->_process as $process) {
|
foreach ($this->runner as $process) {
|
||||||
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,22 +105,11 @@ class ProcessManager extends Component
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|null $name
|
* @param string|null $name
|
||||||
* @param string $tag
|
* @return null|Process
|
||||||
* @return array|Process|null
|
|
||||||
*/
|
*/
|
||||||
public function get(?string $name = null, string $tag = 'default'): array|Process|null
|
public function get(?string $name = null): ?Process
|
||||||
{
|
{
|
||||||
$process = $this->_process[$tag] ?? null;
|
return $this->runner[$name] ?? null;
|
||||||
if (empty($process)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!empty($name)) {
|
|
||||||
if (!isset($process[$name])) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return $process[$name];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,7 +118,7 @@ class ProcessManager extends Component
|
|||||||
*/
|
*/
|
||||||
public function stop(): void
|
public function stop(): void
|
||||||
{
|
{
|
||||||
foreach ($this->_process as $process) {
|
foreach ($this->runner as $process) {
|
||||||
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
Process::kill($process->pid, 0) && Process::kill($process->pid, 15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,11 +147,7 @@ class ProcessManager extends Component
|
|||||||
*/
|
*/
|
||||||
public function push(string $name, string $message): void
|
public function push(string $name, string $message): void
|
||||||
{
|
{
|
||||||
if (!isset($this->_process[$name])) {
|
$this->runner[$name]?->write($message);
|
||||||
return;
|
|
||||||
}
|
|
||||||
$process = $this->_process[$name];
|
|
||||||
$process->write($message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user