kphp
kphp copied to clipboard
SIGTERM is not handled properly in CLI / --once modes
Problem
KPHP compiled program in CLI/--once modes do not handle SIGTERM signal properly:
- after first SIGTERM nothing happens for indefinite time
- after second SIGTERM application exits but does not call functions registered by
register_shutdown_function
Test code
<?php
register_shutdown_function(function () {
var_dump('shutting down');
});
$start = microtime(true);
while (true) {
sleep(1);
$elapsed = (int)(microtime(true) - $start);
var_dump("working for ${elapsed} seconds");
}
Compilation
cli mode:
kphp -M cli ./test.php
normal mode
kphp ./test.php
Run
Server --once
mode and CLI mode have the same behavior:
./kphp_out/server --once --sigterm-wait-time 1 & # OR ./kphp_out/cli &
string(21) "working for 1 seconds"
string(21) "working for 2 seconds"
string(21) "working for 3 seconds"
string(21) "working for 4 seconds"
string(21) "working for 5 seconds"
string(21) "working for 6 seconds"
string(21) "working for 7 seconds"
string(21) "working for 8 seconds"
string(21) "working for 9 seconds" <--------------- kill $!
[pid 223] [time 1686236327] SIGTERM handled.
string(21) "working for 9 seconds"
string(22) "working for 10 seconds"
string(22) "working for 11 seconds"
string(22) "working for 12 seconds"
string(22) "working for 13 seconds"
string(22) "working for 14 seconds"
string(22) "working for 15 seconds"
string(22) "working for 16 seconds" <--------------- kill $! again
[pid 223] [time 1686236334] SIGTERM handled immediately.