1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00
amp/examples/006_libuv_signal_handling.php

30 lines
967 B
PHP
Raw Normal View History

2014-08-06 22:01:40 +02:00
<?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';
2014-08-06 22:01:40 +02:00
2014-09-23 04:38:32 +02:00
(new Amp\UvReactor)->run(function($reactor) {
2014-08-06 22:01:40 +02:00
// 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;
});
});