Skip to content

Commit 28aedbd

Browse files
committed
[php] Handle SIGINT and SIGTERM in ReactPHP
Although this isn't a huge deal, it speeds up development as we don't need to wait docker to trigger SIGKILL. Signed-off-by: Luís Cobucci <[email protected]>
1 parent 72db1be commit 28aedbd

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

frameworks/PHP/reactphp/reactphp.dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ COPY . .
2727

2828
EXPOSE 8080
2929

30-
CMD php server.php
30+
ENTRYPOINT ["/usr/bin/php"]
31+
CMD ["server.php"]

frameworks/PHP/reactphp/server.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@
1616
echo "React Server running at http://0.0.0.0:8080\n";
1717
echo "EventLoop: ", Loop::get()::class, "\n";
1818

19+
$interrupt = static function () use ($server, $socket, &$interrupt): void {
20+
echo 'Interrupting server', PHP_EOL;
21+
22+
$socket->close();
23+
24+
Loop::removeSignal(SIGINT, $interrupt);
25+
Loop::removeSignal(SIGTERM, $interrupt);
26+
};
27+
28+
Loop::addSignal(SIGINT, $interrupt);
29+
Loop::addSignal(SIGTERM, $interrupt);

0 commit comments

Comments
 (0)