Skip to content

Commit

Permalink
update: synchronize ripple changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cclilshy committed Oct 11, 2024
1 parent 6b90cf7 commit 7b8fba0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 97 deletions.
52 changes: 4 additions & 48 deletions src/Laravel/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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+'));
Expand All @@ -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);
}
}
56 changes: 7 additions & 49 deletions src/ThinkPHP/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@

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;
use Psc\Drive\Utils\Console;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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';
}

/**
Expand Down Expand Up @@ -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';
}

/**
* 子进程启动流程,发生于子进程中
*
Expand Down Expand Up @@ -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);
}

# 根据响应类型处理响应内容
Expand All @@ -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);
}
}

0 comments on commit 7b8fba0

Please sign in to comment.