Skip to content

Commit f03913a

Browse files
authored
Fix max_execution_time config doesn't work (#510)
* Fix max_execution_time config doesn't work * Add extension_loaded swoole verify * Update EnsureRequestsDontExceedMaxExecutionTime.php * Update EnsureRequestsDontExceedMaxExecutionTime.php
1 parent 85dcacf commit f03913a

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

bin/createSwooleTimerTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
$timerTable->column('worker_pid', Table::TYPE_INT);
1212
$timerTable->column('time', Table::TYPE_INT);
13+
$timerTable->column('fd', Table::TYPE_INT);
1314

1415
$timerTable->create();
1516

bin/swoole-server

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ $server->on('request', function ($request, $response) use ($server, $workerState
107107
$workerState->timerTable->set($workerState->workerId, [
108108
'worker_pid' => $workerState->workerPid,
109109
'time' => time(),
110+
'fd' => $request->fd,
110111
]);
111112
}
112113

src/Swoole/Actions/EnsureRequestsDontExceedMaxExecutionTime.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
namespace Laravel\Octane\Swoole\Actions;
44

55
use Laravel\Octane\Swoole\SwooleExtension;
6+
use Swoole\Http\Response;
7+
use Swoole\Http\Server;
68

79
class EnsureRequestsDontExceedMaxExecutionTime
810
{
911
public function __construct(
1012
protected SwooleExtension $extension,
1113
protected $timerTable,
12-
protected $maxExecutionTime
14+
protected $maxExecutionTime,
15+
protected ?Server $server = null
1316
) {
1417
}
1518

@@ -25,6 +28,12 @@ public function __invoke()
2528
$this->timerTable->del($workerId);
2629

2730
$this->extension->dispatchProcessSignal($row['worker_pid'], SIGKILL);
31+
32+
if ($this->server instanceof Server) {
33+
$response = Response::create($this->server, $row['fd']);
34+
$response->status(408);
35+
$response->end();
36+
}
2837
}
2938
}
3039
}

src/Swoole/Handlers/OnServerStart.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public function __invoke($server)
4343
}
4444

4545
if ($this->maxExecutionTime > 0) {
46-
$server->tick(1000, function () {
46+
$server->tick(1000, function () use ($server) {
4747
(new EnsureRequestsDontExceedMaxExecutionTime(
48-
$this->extension, $this->timerTable, $this->maxExecutionTime
48+
$this->extension, $this->timerTable, $this->maxExecutionTime, $server
4949
))();
5050
});
5151
}

0 commit comments

Comments
 (0)