/** * Handler of the SIGTERM (graceful shutdown) signal in worker process. * @return void */ protected function sigterm() { if (Daemon::$config->logsignals->value) { $this->log('caught SIGTERM.'); } $this->graceful = false; $this->breakMainLoop = true; $this->eventBase->exit(); }
<?php error_reporting(E_ALL); $read_timeout = 3; $write_timeout = 3; $delay = 5; $timer = null; $base = new EventBase(); connect_dest(); while (1) { $base->exit(2); $base->dispatch(); } function connect_dest() { global $read_timeout, $write_timeout; echo "connect dest...\n"; global $base; $buffer = new EventBufferEvent($base, NULL, EventBufferEvent::OPT_CLOSE_ON_FREE | EventBufferEvent::OPT_DEFER_CALLBACKS, 'readcb', null, 'eventcb', $base); $buffer->enable(Event::READ); $buffer->setTimeouts($read_timeout, $write_timeout); $buffer->connect('127.0.0.1:8000'); $buffer->write('client data, ' . time()); } function readcb($buffer, $base) { global $delay; echo "read running...\n"; echo $buffer->read(1024), "\n"; $buffer->enable(Event::WRITE); $buffer->setCallbacks('readcb', 'writecb', 'eventcb');
public function exit() { $this->base->exit(); }
<?php function print_line($fd, $what, $base) { echo fgets($fd); } $base = new EventBase(); $event = new Event($base, STDIN, Event::READ | Event::PERSIST, 'print_line', $base); $event->add(); while (1) { $base->exit(6); echo '===========debug===========' . PHP_EOL; $base->loop(); }