• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP event_base_set函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中event_base_set函数的典型用法代码示例。如果您正苦于以下问题:PHP event_base_set函数的具体用法?PHP event_base_set怎么用?PHP event_base_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了event_base_set函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct($port)
 {
     global $errno, $errstr;
     if (!extension_loaded('libevent')) {
         die("Please install libevent extension firstly\n");
     }
     if ($port < 1024) {
         die("Port must be a number which bigger than 1024\n");
     }
     $socket_server = stream_socket_server("tcp://0.0.0.0:{$port}", $errno, $errstr);
     if (!$socket_server) {
         die("{$errstr} ({$errno})");
     }
     stream_set_blocking($socket_server, 0);
     // 非阻塞
     // event_base_new — Create and initialize new event base
     $base = event_base_new();
     // event_new — Create new event
     $event = event_new();
     // event_set — Prepare an event
     event_set($event, $socket_server, EV_READ | EV_PERSIST, [__CLASS__, 'ev_accept'], $base);
     // event_base_set — Associate event base with an event
     event_base_set($event, $base);
     // event_add — Add an event to the set of monitored events
     event_add($event);
     // event_base_loop — Handle events
     event_base_loop($base);
     self::$connections = [];
     self::$buffers = [];
 }
开发者ID:CraryPrimitiveMan,项目名称:code-examples,代码行数:30,代码来源:epoll_server.php


示例2: getProcess

 public function getProcess()
 {
     if (!$this->process) {
         $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
         $cmd = PHPBIN . ' -f ' . realpath(__DIR__ . '/../bin/') . '/worker.php';
         $this->process = proc_open($cmd, $descriptorspec, $pipes, '/tmp', array('prefix' => $this->parent->prefix, 'bootstrap' => $this->parent->script, 'verbose' => VERBOSE));
         if ($this->process === false) {
             $error = error_get_last();
             $this->parent->log('Error : unable to start a process - ' . $error['message']);
         } else {
             $this->std_out = $pipes[0];
             $this->std_in = $pipes[1];
             $this->std_err = $pipes[2];
             stream_set_blocking($this->std_in, 0);
             stream_set_blocking($this->std_err, 0);
             VERBOSE && $this->parent->log('Start a new process : ' . $this->process);
             if (function_exists('event_new')) {
                 $this->event = event_new();
                 event_set($this->event, $this->std_in, EV_READ | EV_PERSIST, array($this, 'onRead'), array($this->event, $this->parent->events));
                 event_base_set($this->event, $this->parent->events);
                 event_add($this->event);
             }
         }
     }
     return $this->process;
 }
开发者ID:sergiula,项目名称:php-worker-manager,代码行数:26,代码来源:JobWorker.php


示例3: request

 public function request($method = null)
 {
     if (!$this->uri instanceof Zend_Uri_Http) {
         /** @see Zend_Http_Client_Exception */
         require_once 'Zend/Http/Client/Exception.php';
         throw new Zend_Http_Client_Exception('No valid URI has been passed to the client');
     }
     if ($method) {
         error_log('aaa');
         $this->setMethod($method);
     }
     $uri = $this->uri;
     $port = isset($tmp['port']) ? $tmp['port'] : 80;
     $host = $uri->getHost();
     $port = $uri->getPort();
     $socket = stream_socket_client("{$host}:{$port}", $errno, $errstr, (int) $this->config['timeout'], STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT);
     stream_set_blocking($socket, 0);
     $base = $this->config['eventbase'];
     $writeEvent = event_new();
     event_set($writeEvent, $socket, EV_WRITE, array($this, 'onAccept'), array($writeEvent, $base));
     event_base_set($writeEvent, $base);
     event_add($writeEvent);
     $readEvent = event_new();
     event_set($readEvent, $socket, EV_READ | EV_PERSIST, array($this, 'onRead'), array($readEvent, $base));
     event_base_set($readEvent, $base);
     event_add($readEvent);
     if (!empty($callback)) {
         $this->callback = $callback;
     }
 }
开发者ID:happyooboy,项目名称:AsyncHttpClient,代码行数:30,代码来源:AsyncHttpClient.php


示例4: createEvent

 /**
  * {@inheritdoc}
  */
 protected function createEvent($base, SocketEventInterface $socket, callable $callback)
 {
     $event = event_new();
     event_set($event, $socket->getResource(), EV_WRITE, $callback, $socket);
     event_base_set($event, $base);
     return $event;
 }
开发者ID:kayandrae,项目名称:icicle,代码行数:10,代码来源:AwaitManager.php


示例5: EpollSocketServer

 function EpollSocketServer($port)
 {
     global $errno, $errstr;
     if (!extension_loaded('libevent')) {
         die("Please install libevent extension firstly/n");
     }
     if ($port < 1024) {
         die("Port must be a number which bigger than 1024/n");
     }
     $socket_server = stream_socket_server("tcp://0.0.0.0:{$port}", $errno, $errstr);
     if (!$socket_server) {
         die("{$errstr} ({$errno})");
     }
     stream_set_blocking($socket_server, 0);
     // 非阻塞
     $base = event_base_new();
     $event = event_new();
     event_set($event, $socket_server, EV_READ | EV_PERSIST, array(__CLASS__, 'ev_accept'), $base);
     event_base_set($event, $base);
     event_add($event);
     event_base_loop($base);
     self::$connections = array();
     self::$buffers = array();
     self::$imei = array();
 }
开发者ID:noikiy,项目名称:mygit,代码行数:25,代码来源:php_socketserver_epoll2.php


示例6: start

 public function start()
 {
     $this->base = event_base_new();
     if ($this->_server) {
         $this->event = event_new();
         event_set($this->event, $this->_server, EV_READ | EV_PERSIST, array($this, 'accept'), $this->base);
         event_base_set($this->event, $this->base);
         event_add($this->event);
     }
     foreach ($this->_services as $serviceId => $service) {
         $event = event_new();
         event_set($event, $service, EV_READ | EV_PERSIST | EV_WRITE, array($this, 'service'), $this->base);
         event_base_set($event, $this->base);
         event_add($event);
         $this->events[$serviceId] = $event;
     }
     if ($this->timer) {
         $timer = event_timer_new();
         event_timer_set($timer, array($this, '_onTimer'), $timer);
         event_base_set($timer, $this->base);
         //event_timer_pending($timer, $this->timer * 1000000);
         event_timer_add($timer, $this->timer * 1000000);
     }
     event_base_loop($this->base);
 }
开发者ID:JimboOneTwo,项目名称:websocket,代码行数:25,代码来源:WebsocketGenericLibevent.php


示例7: start

 public function start()
 {
     $this->onStart();
     $this->base = event_base_new();
     if ($this->_server) {
         $this->event = event_new();
         event_set($this->event, $this->_server, EV_READ | EV_PERSIST, array($this, 'accept'), $this->base);
         event_base_set($this->event, $this->base);
         event_add($this->event);
     }
     if ($this->_service) {
         $this->service_event = event_new();
         event_set($this->service_event, $this->_service, EV_READ | EV_PERSIST, array($this, 'service'), $this->base);
         event_base_set($this->service_event, $this->base);
         event_add($this->service_event);
     }
     if ($this->_master) {
         $this->master_event = event_new();
         event_set($this->master_event, $this->_master, EV_READ | EV_PERSIST | EV_WRITE, array($this, 'master'), $this->base);
         event_base_set($this->master_event, $this->base);
         event_add($this->master_event);
     }
     if ($this->timer) {
         $timer = event_timer_new();
         event_timer_set($timer, array($this, '_onTimer'), $timer);
         event_base_set($timer, $this->base);
         //event_timer_pending($timer, $this->timer * 1000000);
         event_timer_add($timer, $this->timer * 1000000);
     }
     event_base_loop($this->base);
 }
开发者ID:morozovsk,项目名称:websocket,代码行数:31,代码来源:GenericLibevent.php


示例8: 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


示例9: start

 public function start()
 {
     self::$_logger->info('Server starts.');
     // Init a non-blocking TCP socket for listening
     $this->_sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
     if (!$this->_sock) {
         $errno = socket_last_error();
         $errstr = socket_strerror($errno);
         self::$_logger->err("Socket create error: {$errstr} ({$errno})");
         die;
     }
     socket_set_nonblock($this->_sock);
     if (!socket_bind($this->_sock, $this->_addr, $this->_port)) {
         $errno = socket_last_error();
         $errstr = socket_strerror($errno);
         self::$_logger->err("Socket bind error: {$errstr} ({$errno})");
         die;
     }
     if (!socket_listen($this->_sock, $this->_listenQueue)) {
         $errno = socket_last_error();
         $errstr = socket_strerror($errno);
         self::$_logger->err("Socket listen error: {$errstr} ({$errno})");
         die;
     }
     // For the listening socket, we use raw event to handle it.
     $this->_listenEvent = event_new();
     event_set($this->_listenEvent, $this->_sock, EV_READ | EV_PERSIST, array($this, 'handleAcceptEvent'));
     event_base_set($this->_listenEvent, $this->_eventBase);
     event_add($this->_listenEvent);
     // Endless loop
     $this->_started = TRUE;
     event_base_loop($this->_eventBase);
     // The loop ends here.
     $this->stop();
 }
开发者ID:BGCX261,项目名称:zoptimizer-svn-to-git,代码行数:35,代码来源:server.php


示例10: connectTo

 public function connectTo($host, $port, $blockConnect = false)
 {
     Debug::netEvent(get_class($this) . '::' . __METHOD__ . '(' . $host . ':' . $port . ') invoked.');
     $connSocket = stream_socket_client("tcp://{$host}:{$port}", $errno, $errstr, 30);
     //add err connect
     stream_set_blocking($connSocket, 0);
     if (!is_resource($connSocket)) {
         Debug::netErrorEvent(get_class($this) . ': can not add errorneus socket with address \'' . $host . ':' . $port . '\'.');
         return false;
     }
     $connId = daemon::getNextSocketId();
     //@todo 增加阻塞 connect , 这样可以返回 connId 的时候 socketSession 已经建立好
     if ($blockConnect) {
     }
     $ev = event_new();
     // why not use EV_PERSIST, is because first event is acceptEvent?
     if (!event_set($ev, $connSocket, EV_WRITE, array($this, 'onConnectedEvent'), array($connId))) {
         Debug::netErrorEvent(get_class($this) . '::' . __METHOD__ . ': can not set onAcceptEvent() on binded socket: ' . Debug::dump($connSocket));
         return false;
     }
     event_base_set($ev, daemon::$eventBase);
     event_add($ev, 1 * 1000 * 1000);
     $this->checkConnSocketPool[$connId] = $connSocket;
     $this->checkConnEvPool[$connId] = $ev;
     return $connId;
 }
开发者ID:ansendu,项目名称:ansio,代码行数:26,代码来源:AsyncClient.php


示例11: onAccept

 public function onAccept($listener, $what, $arg)
 {
     $socket = stream_socket_accept($listener, 5000);
     if (!$socket) {
         echo "Invalid fd\n";
         return;
     }
     echo "Accept new socket ({$socket})\n";
     //    echo "Peer name=" . $this->peername($socket) . "\n";
     //    echo "Sock name=" . $this->sockname($socket) . "\n";
     stream_set_blocking($socket, 0);
     //    stream_set_timeout($socket, 5000);
     $readEvent = event_new();
     $writeEvent = event_new();
     if (!$readEvent || !$writeEvent) {
         echo "Unable to create read or write event ({$socket})\n";
         $this->close($socket);
     }
     event_set($readEvent, $socket, EV_READ | EV_PERSIST, array($this, 'onRead'), null);
     event_set($writeEvent, $socket, EV_WRITE | EV_PERSIST, array($this, 'onWrite'), null);
     event_base_set($readEvent, $this->base);
     event_base_set($writeEvent, $this->base);
     $this->sockets[(int) $socket] = ['readEvent' => $readEvent, 'writeEvent' => $writeEvent];
     event_add($readEvent, -1);
 }
开发者ID:sokal32,项目名称:ranch-cowboy-smoothie-php-draft,代码行数:25,代码来源:ranch_tcp.php


示例12: addWriteStream

 public function addWriteStream($stream, $listener)
 {
     $event = event_new();
     event_set($event, $stream, EV_READ | EV_PERSIST, $listener);
     event_base_set($event, $this->base);
     event_add($event);
     $this->events[(int) $stream] = $event;
 }
开发者ID:romainneutron,项目名称:SocketServer,代码行数:8,代码来源:LibEventLoop.php


示例13: addSignal

 /**
  * Add signal handler.
  *
  * @param $signal
  * @param $callback
  * @return bool
  */
 public function addSignal($signal, $callback)
 {
     $event = event_new();
     $this->_signalEvents[$signal] = $event;
     event_set($event, $signal, EV_SIGNAL | EV_PERSIST, $callback);
     event_base_set($event, $this->_eventBase);
     event_add($event);
 }
开发者ID:walkor,项目名称:workerman,代码行数:15,代码来源:LibEventLoop.php


示例14: onConnect

 public function onConnect()
 {
     $clientSocket = stream_socket_accept($this->handle_);
     stream_set_blocking($clientSocket, 0);
     $clientEvent = event_new();
     \event_set($clientEvent, $clientSocket, EV_READ | EV_PERSIST, array($this, 'onRequest'), array($clientEvent));
     \event_base_set($clientEvent, $this->base_);
     event_add($clientEvent);
 }
开发者ID:kaiyulee,项目名称:thrift-lib-php,代码行数:9,代码来源:TNonblockingServerSocket.php


示例15: accept_cb

function accept_cb($socket, $flag, $base)
{
    $conn = stream_socket_accept($socket, 0);
    stream_set_blocking($conn, 0);
    $event = event_new();
    event_set($event, $conn, EV_READ | EV_PERSIST, read_cb, $base);
    event_base_set($event, $base);
    event_add($event);
}
开发者ID:silentred,项目名称:learning-path,代码行数:9,代码来源:stream+-v3.php


示例16: setTimeout

 public function setTimeout($callback, $interval_ms)
 {
     $base = \Event\Emitter::getBase();
     $event = event_timer_new();
     $arg = array($callback, $event, $interval_ms);
     event_timer_set($event, array($this, 'ev_timer'), $arg);
     event_base_set($event, $base);
     event_add($event, $interval_ms * 1000);
 }
开发者ID:hinathan,项目名称:edges-php,代码行数:9,代码来源:Timer.php


示例17: start

 /**
  * {@inheritdoc}
  */
 public function start(Timer $timer)
 {
     if (!isset($this->timers[$timer])) {
         $event = event_new();
         event_timer_set($event, $this->callback, $timer);
         event_base_set($event, $this->base);
         $this->timers[$timer] = $event;
         event_add($event, $timer->getInterval() * self::MICROSEC_PER_SEC);
     }
 }
开发者ID:valentinkh1,项目名称:icicle,代码行数:13,代码来源:LibeventTimerManager.php


示例18: add

 function add($event)
 {
     $ev = event_new();
     event_set($ev, $event->fd, $event->events, function () use($event) {
         call_user_func($event->callback, $event);
     });
     event_base_set($ev, $this->handle);
     event_add($ev);
     $event->base = $this;
     $event->handle = $ev;
     return $this;
 }
开发者ID:chh,项目名称:eventor,代码行数:12,代码来源:Base.php


示例19: run

 /**
  * 运行服务器程序
  * @return unknown_type
  */
 function run()
 {
     //初始化事件系统
     $this->init();
     //建立服务器端Socket
     $this->server_sock = $this->create("udp://{$this->host}:{$this->port}");
     //设置事件监听,监听到服务器端socket可读,则有连接请求
     event_set($this->server_event, $this->server_sock, EV_READ | EV_PERSIST, "sw_server_handle_recvfrom", $this);
     event_base_set($this->server_event, $this->base_event);
     event_add($this->server_event);
     $this->protocol->onStart();
     event_base_loop($this->base_event);
 }
开发者ID:jasonshaw,项目名称:framework-1,代码行数:17,代码来源:EventUDP.php


示例20: __construct

 /**
  * @param \Icicle\Loop\LoopInterface $loop
  * @param \Icicle\Loop\Events\EventFactoryInterface $factory
  * @param resource $base
  */
 public function __construct(LibeventLoop $loop, EventFactoryInterface $factory)
 {
     parent::__construct($loop, $factory);
     $callback = $this->createSignalCallback();
     $base = $loop->getEventBase();
     foreach ($this->getSignalList() as $signo) {
         $event = event_new();
         event_set($event, $signo, EV_SIGNAL | EV_PERSIST, $callback);
         event_base_set($event, $base);
         event_add($event);
         $this->events[$signo] = $event;
     }
 }
开发者ID:kayandrae,项目名称:icicle,代码行数:18,代码来源:SignalManager.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP event_change_pageby函数代码示例发布时间:2022-05-15
下一篇:
PHP event_base_new函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap