1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00
amp/examples/006_libuv_signal_handling.php
2014-12-26 15:29:51 -02:00

30 lines
967 B
PHP

<?php
/**
* Process signals are "watchable" events just like timers and stream IO
* availability. SignalReactor::onSignal() returns a unique watcher ID that
* may be disabled/enabled/cancelled like any other watcher.
*
* The available signal number constants vary by operating system, but you
* can see the possible signals in your PHP install with the following
* snippet:
*
* <?php
* // Any constant beginning with SIG* is an available signal
* print_r((new ReflectionClass('UV'))->getConstants());
*/
require __DIR__ . '/../vendor/autoload.php';
(new Amp\UvReactor)->run(function($reactor) {
// Let's tick off output once per second so we can see activity.
$reactor->repeat(function() {
echo "tick: ", date('c'), "\n";
}, $msInterval = 1000);
// What to do when a SIGINT signal is received
$reactor->onSignal(UV::SIGINT, function() {
echo "Caught SIGINT! exiting ...\n";
exit;
});
});