4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
13 * Runs a PHP script that can be stopped only with a SIGKILL (9) signal for 3 seconds.
15 * @args duration Run this script with a custom duration
17 * @example `php NonStopableProcess.php 42` will run the script for 42 seconds
19 function handleSignal($signal)
29 $name = $signal.' (unknown)';
33 echo "signal $name\n";
36 pcntl_signal(SIGTERM, 'handleSignal');
37 pcntl_signal(SIGINT, 'handleSignal');
41 $duration = isset($argv[1]) ? (int) $argv[1] : 3;
42 $start = microtime(true);
44 while ($duration > (microtime(true) - $start)) {
46 pcntl_signal_dispatch();