2021-11-03 15:17:52 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Server\Abstracts;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use JetBrains\PhpStorm\Pure;
|
2021-11-18 11:37:12 +08:00
|
|
|
use Server\Contract\OnProcessInterface;
|
2021-11-03 15:17:52 +08:00
|
|
|
use Swoole\Coroutine;
|
|
|
|
|
use Swoole\Process;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
abstract class BaseProcess implements OnProcessInterface
|
|
|
|
|
{
|
|
|
|
|
|
2021-11-03 17:39:08 +08:00
|
|
|
protected bool $isStop = false;
|
2021-11-03 15:17:52 +08:00
|
|
|
|
|
|
|
|
|
2021-11-03 17:39:08 +08:00
|
|
|
protected mixed $redirect_stdin_and_stdout = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected int $pipe_type = SOCK_DGRAM;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected bool $enable_coroutine = true;
|
|
|
|
|
|
|
|
|
|
|
2021-11-03 17:43:34 +08:00
|
|
|
public string $name = 'swoole process.';
|
2021-11-03 17:39:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getName(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isStop(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->isStop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function getRedirectStdinAndStdout(): mixed
|
|
|
|
|
{
|
|
|
|
|
return $this->redirect_stdin_and_stdout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function getPipeType(): int
|
|
|
|
|
{
|
|
|
|
|
return $this->pipe_type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isEnableCoroutine(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->enable_coroutine;
|
|
|
|
|
}
|
2021-11-03 15:17:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function onProcessStop(): void
|
|
|
|
|
{
|
|
|
|
|
$this->isStop = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|