2021-03-18 14:56:35 +08:00
|
|
|
<?php /** @noinspection PhpUnused */
|
2021-01-20 16:11:04 +08:00
|
|
|
|
|
|
|
|
|
2021-06-16 00:17:30 +08:00
|
|
|
namespace ZM\Utils\Manager;
|
2021-01-20 16:11:04 +08:00
|
|
|
|
|
|
|
|
|
2022-03-13 22:04:52 +08:00
|
|
|
use Swoole\Process;
|
2021-03-24 23:34:46 +08:00
|
|
|
|
2021-01-20 16:11:04 +08:00
|
|
|
class ProcessManager
|
|
|
|
|
{
|
2022-03-13 22:04:52 +08:00
|
|
|
/** @var Process[] */
|
|
|
|
|
public static $user_process = [];
|
2021-03-24 23:34:46 +08:00
|
|
|
|
2022-03-13 22:04:52 +08:00
|
|
|
/**
|
|
|
|
|
* @param string $name
|
|
|
|
|
* @param callable $callable
|
|
|
|
|
* @return Process
|
|
|
|
|
*/
|
|
|
|
|
public static function createUserProcess(string $name, callable $callable): Process
|
|
|
|
|
{
|
|
|
|
|
return self::$user_process[$name] = new Process($callable);
|
2021-03-24 23:34:46 +08:00
|
|
|
}
|
|
|
|
|
|
2022-03-13 22:04:52 +08:00
|
|
|
/**
|
|
|
|
|
* @param string $string
|
|
|
|
|
* @return Process|null
|
|
|
|
|
*/
|
|
|
|
|
public static function getUserProcess(string $string): ?Process
|
|
|
|
|
{
|
|
|
|
|
return self::$user_process[$string] ?? null;
|
2021-01-20 16:11:04 +08:00
|
|
|
}
|
|
|
|
|
}
|