diff --git a/src/Laravel/Worker.php b/src/Laravel/Worker.php index abf3d11..a9b46bb 100644 --- a/src/Laravel/Worker.php +++ b/src/Laravel/Worker.php @@ -39,7 +39,6 @@ use Illuminate\Contracts\Http\Kernel; use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Config; -use JetBrains\PhpStorm\NoReturn; use Psc\Core\Http\Server\Request; use Psc\Core\Http\Server\Server; use Psc\Drive\Laravel\Events\RequestHandled; @@ -51,14 +50,12 @@ use Psc\Drive\Utils\Console; use Psc\Drive\Utils\Guard; use Psc\Utils\Output; -use Psc\Worker\Command; use Psc\Worker\Manager; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Throwable; use function base_path; use function cli_set_process_title; -use function Co\cancelAll; use function file_exists; use function fopen; use function fwrite; @@ -87,9 +84,11 @@ class Worker extends \Psc\Worker\Worker */ public function __construct( private readonly string $address = 'http://127.0.0.1:8008', - private readonly int $count = 4, + int $count = 4, private readonly bool $sandbox = true, ) { + $this->name = 'http-server'; + $this->count = $count; } /** @@ -151,16 +150,6 @@ public function register(Manager $manager): void } } - /** - * @Author cclilshy - * @Date 2024/8/17 11:06 - * @return string - */ - public function getName(): string - { - return 'http-server'; - } - /** * @Author cclilshy * @Date 2024/8/17 11:08 @@ -196,7 +185,7 @@ public function boot(): void $response = $request->getResponse(); $response->setStatusCode($laravelResponse->getStatusCode()); foreach ($laravelResponse->headers->all() as $key => $value) { - $response->setHeader($key, $value); + $response->withHeader($key, $value); } if ($laravelResponse instanceof BinaryFileResponse) { $response->setContent(fopen($laravelResponse->getFile()->getPathname(), 'r+')); @@ -222,37 +211,4 @@ public function boot(): void }); $this->server->listen(); } - - /** - * @Author cclilshy - * @Date 2024/8/17 11:06 - * @return int - */ - public function getCount(): int - { - return $this->count; - } - - /** - * @Author cclilshy - * @Date 2024/8/16 23:39 - * - * @param Command $workerCommand - * - * @return void - */ - public function onCommand(Command $workerCommand): void - { - } - - /** - * @Author cclilshy - * @Date 2024/8/17 11:35 - * @return void - */ - #[NoReturn] public function onReload(): void - { - cancelAll(); - exit(0); - } } diff --git a/src/ThinkPHP/Worker.php b/src/ThinkPHP/Worker.php index 3e7a1c9..67fe387 100644 --- a/src/ThinkPHP/Worker.php +++ b/src/ThinkPHP/Worker.php @@ -36,7 +36,6 @@ use Co\IO; use Co\Net; -use JetBrains\PhpStorm\NoReturn; use Psc\Core\Http\Server\Request; use Psc\Core\Http\Server\Server; use Psc\Drive\Utils\Config; @@ -44,7 +43,6 @@ use Psc\Drive\Utils\Guard; use Psc\Kernel; use Psc\Utils\Output; -use Psc\Worker\Command; use Psc\Worker\Manager; use think\App; use think\facade\Env; @@ -54,7 +52,6 @@ use function app; use function cli_set_process_title; -use function Co\cancelAll; use function Co\repeat; use function file_exists; use function fwrite; @@ -87,8 +84,12 @@ class Worker extends \Psc\Worker\Worker * @param string $address * @param int $count */ - public function __construct(private readonly string $address = 'http://127.0.0.1:8008', private readonly int $count = 4) - { + public function __construct( + private readonly string $address = 'http://127.0.0.1:8008', + int $count = 4 + ) { + $this->count = $count; + $this->name = 'http-server'; } /** @@ -143,16 +144,6 @@ public function register(Manager $manager): void } } - /** - * @Author cclilshy - * @Date 2024/8/17 11:06 - * @return string - */ - public function getName(): string - { - return 'http-server'; - } - /** * 子进程启动流程,发生于子进程中 * @@ -208,7 +199,7 @@ public function boot(): void $response->setStatusCode($thinkResponse->getCode()); foreach ($thinkResponse->getHeader() as $key => $value) { - $response->setHeader($key, $value); + $response->withHeader($key, $value); } # 根据响应类型处理响应内容 @@ -222,37 +213,4 @@ public function boot(): void }); $this->server->listen(); } - - /** - * @Author cclilshy - * @Date 2024/8/17 11:06 - * @return int - */ - public function getCount(): int - { - return $this->count; - } - - /** - * @Author cclilshy - * @Date 2024/8/16 23:39 - * - * @param Command $workerCommand - * - * @return void - */ - public function onCommand(Command $workerCommand): void - { - } - - /** - * @Author cclilshy - * @Date 2024/8/17 11:35 - * @return void - */ - #[NoReturn] public function onReload(): void - { - cancelAll(); - exit(0); - } }