本文整理汇总了PHP中event_base_loopexit函数的典型用法代码示例。如果您正苦于以下问题:PHP event_base_loopexit函数的具体用法?PHP event_base_loopexit怎么用?PHP event_base_loopexit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了event_base_loopexit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: httpGet
function httpGet($host, $base_fd)
{
global $index;
$fd = stream_socket_client("{$host}", $errno, $errstr, 3, STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT);
$index[$fd] = 0;
$event_fd = event_new();
event_set($event_fd, $fd, EV_WRITE | EV_PERSIST, function ($fd, $events, $arg) use($host) {
global $times, $limit, $index;
if (!$index[$fd]) {
$index[$fd] = 1;
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: {$host}\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fd, $out);
} else {
$str = fread($fd, 4096);
echo $str, PHP_EOL;
if (feof($fd)) {
fclose($fd);
$times++;
echo "done\n";
if ($times == $limit - 1) {
event_base_loopexit($arg[1]);
}
}
}
}, array($event_fd, $base_fd));
event_base_set($event_fd, $base_fd);
event_add($event_fd);
}
示例2: shutdown
/**
* 关闭服务器程序
* @return unknown_type
*/
function shutdown()
{
//关闭服务器端
sw_socket_close($this->server_sock, $this->server_event);
//关闭事件循环
event_base_loopexit($this->base_event);
$this->protocol->onShutdown();
}
示例3: print_line
function print_line($fd, $events, $arg)
{
echo "callback fired" . PHP_EOL;
var_dump($arg[0]->recv());
$arg[0]->send("got msg " . ZmqController::$msgs);
if (ZmqController::$msgs++ >= 10) {
event_base_loopexit($arg[1]);
}
}
示例4: foo2
function foo2($buf, $arg)
{
static $i;
$i++;
if ($i == 10) {
event_base_loopexit($arg);
}
var_dump($buf);
var_dump(event_buffer_read($buf, 10));
}
示例5: destroyResource
/**
* Destroy libevent resource if it is opened
*
* @return void
*/
private function destroyResource()
{
foreach ($this->events as $event) {
$this->removeEvent($event);
}
if ($this->handle) {
event_base_loopexit($this->handle, 1);
event_base_free($this->handle);
$this->handle = null;
}
}
示例6: print_line
function print_line($fd, $events, $arg)
{
static $max_requests = 0;
$max_requests++;
if ($max_requests == 10) {
// exit loop after 10 writes
event_base_loopexit($arg[1]);
}
// print the line
echo fgets($fd);
}
示例7: shutdown
/**
* 关闭服务器程序
* @return unknown_type
*/
function shutdown()
{
//关闭所有客户端
foreach ($this->client_sock as $k => $sock) {
Stream::close($sock, $this->client_event[$k]);
}
//关闭服务器端
Stream::close($this->server_sock, $this->server_event);
//关闭事件循环
event_base_loopexit($this->base_event);
$this->protocol->onShutdown($this);
}
示例8: print_line
function print_line($fd, $events, $arg)
{
static $msgs = 1;
echo "CALLBACK FIRED" . PHP_EOL;
if ($arg[0]->getsockopt(ZMQ::SOCKOPT_EVENTS) & ZMQ::POLL_IN) {
echo "Got incoming data" . PHP_EOL;
var_dump($arg[0]->recv());
$arg[0]->send("Got msg {$msgs}");
if ($msgs++ >= 10) {
event_base_loopexit($arg[1]);
}
}
}
示例9: test
function test()
{
$count = 0;
$listener = new ZLogger\Listener('tcp://127.0.0.1:5555');
ok($listener);
$listener->recv(function ($e, $arg) use(&$count) {
$count++;
event_base_loopexit($arg[1]);
});
$queue = new ZMQSocket(new ZMQContext(), ZMQ::SOCKET_REQ, "MySock1");
ok($queue);
$queue->connect("tcp://127.0.0.1:5555");
$encoder = new ZLogger\Encoder();
// Assign socket 1 to the queue, send and receive
// var_dump($queue->send("hello there!")->recv());
$text = $encoder(array('msg' => 'text'));
// $listener->listen();
# $queue->send($text);
# ok( $count );
}
示例10: stop
public function stop()
{
// @codeCoverageIgnoreStart
event_base_loopexit($this->base);
// @codeCoverageIgnoreEnd
}
示例11: shutdown
/**
* @todo description?
* @param boolean - Hard? If hard, we shouldn't wait for graceful shutdown of the running applications.
* @return boolean - Ready?
*/
public function shutdown($hard = FALSE)
{
$error = error_get_last();
if ($error) {
if ($error['type'] === E_ERROR) {
Daemon::log('W#' . $this->pid . ' crashed by error \'' . $error['message'] . '\' at ' . $error['file'] . ':' . $error['line']);
}
}
if (Daemon::$config->logevents->value) {
$this->log('event shutdown(' . ($hard ? 'HARD' : '') . ') invoked.');
}
if (Daemon::$config->throwexceptiononshutdown->value) {
throw new Exception('event shutdown');
}
@ob_flush();
if ($this->terminated === TRUE) {
if ($hard) {
exit(0);
}
return;
}
$this->terminated = TRUE;
$this->closeSockets();
$this->setStatus(3);
if ($hard) {
exit(0);
}
$this->reloadReady = $this->appInstancesReloadReady();
if ($this->reload === TRUE) {
$this->reloadReady = $this->reloadReady && microtime(TRUE) > $this->reloadTime;
}
if (Daemon::$config->logevents->value) {
$this->log('reloadReady = ' . Debug::dump($this->reloadReady));
}
$n = 0;
unset(Timer::$list['checkState']);
Timer::add(function ($event) {
$self = Daemon::$process;
$self->reloadReady = $self->appInstancesReloadReady();
if ($self->reload === TRUE) {
$self->reloadReady = $self->reloadReady && microtime(TRUE) > $self->reloadTime;
}
if (!$self->reloadReady) {
$event->timeout();
} else {
event_base_loopexit($self->eventBase);
}
}, 1000000.0, 'checkReloadReady');
while (!$this->reloadReady) {
event_base_loop($this->eventBase);
}
//FS::waitAllEvents(); // ensure that all I/O events completed before suicide
posix_kill(posix_getppid(), SIGCHLD);
// praying to Master
exit(0);
// R.I.P.
}
示例12: shutdown
function shutdown($timeout = -1)
{
event_base_loopexit($this->handle, $timeout);
return $this;
}
示例13: onWriteFailureEvent
public function onWriteFailureEvent($buf, $arg = NULL)
{
if (Daemon::$config->logevents->value) {
Daemon::log(__METHOD__ . '()');
}
if ($this->onWriteFailure !== NULL) {
call_user_func($this->onWriteFailure, $this);
}
event_base_loopexit(Daemon::$process->eventBase);
$this->closeWrite();
}
示例14: stop
function stop()
{
event_base_loopexit($this->base);
}
示例15: unloop
public function unloop()
{
event_base_loopexit($this->event_base);
}