leocarmo / graceful-shutdown-php
Graceful Shutdown for PHP
Installs: 86 903
Dependents: 0
Suggesters: 0
Security: 0
Stars: 18
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- ext-pcntl: *
Requires (Dev)
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9
- symfony/var-dumper: ^5.2
This package is auto-updated.
Last update: 2024-11-29 06:10:54 UTC
README
Generally, a graceful shutdown is preferable in the case of any OS that saves its state. When the standard shutdown procedures are not done with these OSs, the result can be data corruption of program and operating system files. The result of the corruption can be instability, incorrect functioning or failure to boot.
For more information see this.
Composer
composer require leocarmo/graceful-shutdown-php
How to use
This is very simple, you just have to call the check
method inside a while loop and the magic will happen.
use LeoCarmo\GracefulShutdown\GracefulShutdown; $shutdown = new GracefulShutdown(); while (! $shutdown->signalReceived()) { echo 'Start long task...' . PHP_EOL; sleep(sleep(5)); // --> when a signal is sent, sleep returns the number of seconds left echo 'End long task...' . PHP_EOL; } echo 'Graceful shutdown!';
Output result with debug enabled:
Start long task...
End long task...
Start long task...
^C##################### ---> Signal received: [2]
End long task...
Graceful shutdown!
Run make run-exemple
to see this in action
Roadmap
- Tests