コード例 #1
0
ファイル: EventTest.php プロジェクト: omgnull/php-libevent
 /**
  * @param Event $event
  * @depends testEventManualInvoke
  *
  * @return Event
  */
 public function testEventBaseInvoke(Event $event)
 {
     posix_kill(posix_getpid(), SIGUSR1);
     $base = $event->getBase();
     $base->loop();
     $event = new Event($base, 'event_for_loop_exit');
     $event->prepare(SIGHUP, EV_SIGNAL, array($this, 'eventHandlerExitingLoop'), array('test_event'))->enable();
     $event->disable();
     $base->loop();
     return $event;
 }
コード例 #2
0
        echo sprintf("This is a simple sigint event handler. Ivoked by %s \n", $event->getName());
        exit;
    }
}
// Initialize event handler
$eventHandler = new BasicSignalEventHandler();
// Initialize event base
$base = new EventBase();
// Create map of events
$map = array(SIGUSR1 => 'basic_sigusr1_event', SIGINT => 'basic_sigint_event', SIGTERM => 'basic_sigterm_event');
/**
 * Prepare and enable events
 * @var Event $event
 */
foreach ($map as $signal => $name) {
    $event = new Event($base, $name);
    $event->prepare($signal, EV_SIGNAL | EV_PERSIST, array($eventHandler, $name), array($signal))->enable();
}
// Base infinite loop
while (true) {
    // Set loop to non block
    $base->loop(EVLOOP_NONBLOCK);
    // Sleep 3 seconds
    usleep(3000000);
    /**
     * @link http://en.wikipedia.org/wiki/Kill_(command)
     */
    // Next we must send the signals, just uncomment lines with posix functions if you have pisix extension.
    // Also we can send signal from console manualy using kill command, but first need to find out php process pid
    // $ ps axu |grep php
    // and kill or