diff --git a/bin/createSwooleTimerTable.php b/bin/createSwooleTimerTable.php index 756f4518e..3cf369081 100644 --- a/bin/createSwooleTimerTable.php +++ b/bin/createSwooleTimerTable.php @@ -10,6 +10,7 @@ $timerTable->column('worker_pid', Table::TYPE_INT); $timerTable->column('time', Table::TYPE_INT); + $timerTable->column('fd', Table::TYPE_INT); $timerTable->create(); diff --git a/bin/swoole-server b/bin/swoole-server index bcd7a28e4..f2b0c8784 100755 --- a/bin/swoole-server +++ b/bin/swoole-server @@ -107,6 +107,7 @@ $server->on('request', function ($request, $response) use ($server, $workerState $workerState->timerTable->set($workerState->workerId, [ 'worker_pid' => $workerState->workerPid, 'time' => time(), + 'fd' => $request->fd, ]); } diff --git a/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php b/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php index 1f9e1ad49..0902d44f7 100644 --- a/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php +++ b/src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php @@ -3,13 +3,16 @@ namespace Laravel\Octane\Swoole\Actions; use Laravel\Octane\Swoole\SwooleExtension; +use Swoole\Http\Response; +use Swoole\Http\Server; class EnsureRequestsDontExceedMaxExecutionTime { public function __construct( protected SwooleExtension $extension, protected $timerTable, - protected $maxExecutionTime + protected $maxExecutionTime, + protected ?Server $server = null ) { } @@ -25,6 +28,12 @@ public function __invoke() $this->timerTable->del($workerId); $this->extension->dispatchProcessSignal($row['worker_pid'], SIGKILL); + + if ($this->server instanceof Server) { + $response = Response::create($this->server, $row['fd']); + $response->status(408); + $response->end(); + } } } } diff --git a/src/Swoole/Handlers/OnServerStart.php b/src/Swoole/Handlers/OnServerStart.php index bb4614ec2..5cd1f6dfe 100644 --- a/src/Swoole/Handlers/OnServerStart.php +++ b/src/Swoole/Handlers/OnServerStart.php @@ -43,9 +43,9 @@ public function __invoke($server) } if ($this->maxExecutionTime > 0) { - $server->tick(1000, function () { + $server->tick(1000, function () use ($server) { (new EnsureRequestsDontExceedMaxExecutionTime( - $this->extension, $this->timerTable, $this->maxExecutionTime + $this->extension, $this->timerTable, $this->maxExecutionTime, $server ))(); }); }