当前位置: 首页>>代码示例>>PHP>>正文


PHP event_base_loopexit函数代码示例

本文整理汇总了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);
}
开发者ID:CraryPrimitiveMan,项目名称:code-examples,代码行数:30,代码来源:http.php

示例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();
 }
开发者ID:jasonshaw,项目名称:framework-1,代码行数:12,代码来源:EventUDP.php

示例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]);
     }
 }
开发者ID:stonegithubs,项目名称:yaf-lib,代码行数:9,代码来源:Zmq.php

示例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));
}
开发者ID:heartshare,项目名称:VagrantForPhp,代码行数:10,代码来源:libevent.php

示例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;
     }
 }
开发者ID:edefimov,项目名称:async-sockets,代码行数:16,代码来源:LeBase.php

示例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);
}
开发者ID:exakat,项目名称:exakat,代码行数:11,代码来源:Extlibevent.01.php

示例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);
 }
开发者ID:foolkaka,项目名称:soaphp-framework,代码行数:16,代码来源:EventTCP.php

示例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]);
         }
     }
 }
开发者ID:ansendu,项目名称:ZLogger,代码行数:13,代码来源:zmq_server.php

示例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 );
 }
开发者ID:ansendu,项目名称:ZLogger,代码行数:20,代码来源:ListenerTest.php

示例10: stop

 public function stop()
 {
     // @codeCoverageIgnoreStart
     event_base_loopexit($this->base);
     // @codeCoverageIgnoreEnd
 }
开发者ID:ramiyer,项目名称:react,代码行数:6,代码来源:LibEventLoop.php

示例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.
 }
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:62,代码来源:Daemon_WorkerThread.php

示例12: shutdown

 function shutdown($timeout = -1)
 {
     event_base_loopexit($this->handle, $timeout);
     return $this;
 }
开发者ID:chh,项目名称:eventor,代码行数:5,代码来源:Base.php

示例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();
 }
开发者ID:J3FF3,项目名称:phpdaemon,代码行数:11,代码来源:AsyncStream.php

示例14: stop

 function stop()
 {
     event_base_loopexit($this->base);
 }
开发者ID:medehghani,项目名称:alert,代码行数:4,代码来源:LibeventReactor.php

示例15: unloop

 public function unloop()
 {
     event_base_loopexit($this->event_base);
 }
开发者ID:LookForwardPersistence,项目名称:appserver-in-php,代码行数:4,代码来源:LibEventUnbuffered.php


注:本文中的event_base_loopexit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。