mirror of
https://github.com/symfony/process.git
synced 2026-03-23 23:42:06 +01:00
* 6.0: CS fixes Bump Symfony version to 6.0.11 Update VERSION for 6.0.10 Update CHANGELOG for 6.0.10 Bump Symfony version to 5.4.11 Update VERSION for 5.4.10 Update CHANGELOG for 5.4.10 Bump Symfony version to 4.4.44 Update VERSION for 4.4.43 Update CONTRIBUTORS for 4.4.43 Update CHANGELOG for 4.4.43
42 lines
952 B
PHP
42 lines
952 B
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
/**
|
|
* Runs a PHP script that can be stopped only with a SIGKILL (9) signal for 3 seconds.
|
|
*
|
|
* @args duration Run this script with a custom duration
|
|
*
|
|
* @example `php NonStopableProcess.php 42` will run the script for 42 seconds
|
|
*/
|
|
function handleSignal($signal)
|
|
{
|
|
$name = match ($signal) {
|
|
\SIGTERM => 'SIGTERM',
|
|
\SIGINT => 'SIGINT',
|
|
default => $signal.' (unknown)',
|
|
};
|
|
|
|
echo "signal $name\n";
|
|
}
|
|
|
|
pcntl_signal(\SIGTERM, 'handleSignal');
|
|
pcntl_signal(\SIGINT, 'handleSignal');
|
|
|
|
echo 'received ';
|
|
|
|
$duration = isset($argv[1]) ? (int) $argv[1] : 3;
|
|
$start = microtime(true);
|
|
|
|
while ($duration > (microtime(true) - $start)) {
|
|
usleep(10000);
|
|
pcntl_signal_dispatch();
|
|
}
|