本文整理汇总了PHP中event_base_loop函数的典型用法代码示例。如果您正苦于以下问题:PHP event_base_loop函数的具体用法?PHP event_base_loop怎么用?PHP event_base_loop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了event_base_loop函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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
示例2: 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
示例3: __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
示例4: 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
示例5: run
/**
* Runtime of Master process
* @return void
*/
public function run()
{
Daemon::$process = $this;
$this->prepareSystemEnv();
class_exists('Timer');
// ensure loading this class
gc_enable();
$this->eventBase = event_base_new();
$this->registerEventSignals();
FS::initEvent();
$this->fileWatcher = new FileWatcher();
$this->workers = new ThreadCollection();
$this->collections['workers'] = $this->workers;
Daemon::$appResolver = (require Daemon::$config->path->value);
$this->IPCManager = Daemon::$appResolver->getInstanceByAppName('IPCManager');
Daemon::$appResolver->preload(true);
$this->callbacks = new SplStack();
$this->spawnWorkers(min(Daemon::$config->startworkers->value, Daemon::$config->maxworkers->value));
Timer::add(function ($event) use(&$cbs) {
$self = Daemon::$process;
static $c = 0;
++$c;
if ($c > 0xfffff) {
$c = 1;
}
if ($c % 10 == 0) {
$self->workers->removeTerminated(true);
gc_collect_cycles();
} else {
$self->workers->removeTerminated();
}
if (isset(Daemon::$config->mpm->value) && is_callable(Daemon::$config->mpm->value)) {
call_user_func(Daemon::$config->mpm->value);
} else {
// default MPM
$state = Daemon::getStateOfWorkers($self);
if ($state) {
$n = max(min(Daemon::$config->minspareworkers->value - $state['idle'], Daemon::$config->maxworkers->value - $state['alive']), Daemon::$config->minworkers->value - $state['alive']);
if ($n > 0) {
Daemon::log('Spawning ' . $n . ' worker(s).');
$self->spawnWorkers($n);
event_base_loopbreak($self->eventBase);
}
$n = min($state['idle'] - Daemon::$config->maxspareworkers->value, $state['alive'] - Daemon::$config->minworkers->value);
if ($n > 0) {
Daemon::log('Stopping ' . $n . ' worker(s).');
$self->stopWorkers($n);
}
}
}
$event->timeout();
}, 1000000.0 * Daemon::$config->mpmdelay->value, 'MPM');
while (!$this->breakMainLoop) {
while (!$this->callbacks->isEmpty()) {
call_user_func($this->callbacks->shift(), $this);
}
event_base_loop($this->eventBase);
}
}
开发者ID:ruslanchek,项目名称:phpdaemon,代码行数:63,代码来源:Daemon_MasterThread.php
示例6: loop
public function loop()
{
if (!($this->event_base = event_base_new())) {
throw new RuntimeException("Can't create event base");
}
$this->addSocketEvent();
event_base_loop($this->event_base);
}
开发者ID:LookForwardPersistence,项目名称:appserver-in-php,代码行数:8,代码来源:LibEventUnbuffered.php
示例7: dispatch
/**
* {@inheritdoc}
*/
protected function dispatch(bool $blocking)
{
$flags = EVLOOP_ONCE;
if (!$blocking) {
$flags |= EVLOOP_NONBLOCK;
}
event_base_loop($this->base, $flags);
// Dispatch I/O, timer, and signal callbacks.
}
开发者ID:kanzuka,项目名称:icicle,代码行数:12,代码来源:LibeventLoop.php
示例8: loop
public function loop()
{
if (!($this->event_base = event_base_new())) {
throw new RuntimeException("Can't create event base");
}
foreach ($this->addrs as $addr) {
$this->addAddr($addr);
}
event_base_loop($this->event_base);
}
开发者ID:bermi,项目名称:akelos,代码行数:10,代码来源:LibEvent.class.php
示例9: worker_callback
public function worker_callback(swoole_process $worker)
{
self::$worker_event_base[$worker->pipe] = event_base_new();
$event = event_new();
//$GLOBALS['worker'] = $worker;
event_set($event, $worker->pipe, EV_READ | EV_PERSIST, array($this, 'worker_accept'), $worker);
event_base_set($event, self::$worker_event_base[$worker->pipe]);
event_add($event);
event_base_loop(self::$worker_event_base[$worker->pipe]);
}
开发者ID:zhangjingpu,项目名称:yaf-lib,代码行数:10,代码来源:Processpool.php
示例10: doRun
private function doRun($flags = 0)
{
$this->isRunning = TRUE;
event_base_loop($this->base, $flags);
$this->isRunning = FALSE;
if ($this->stopException) {
$e = $this->stopException;
throw $e;
}
}
开发者ID:medehghani,项目名称:alert,代码行数:10,代码来源:LibeventReactor.php
示例11: listen
public function listen()
{
echo "Start listening port " . $this->opts['port'] . "\n";
$socket = stream_socket_server('tcp://0.0.0.0:' . $this->opts['port'], $errno, $errstr);
stream_set_blocking($socket, 0);
$this->base = event_base_new();
$listenerEvent = event_new();
event_set($listenerEvent, $socket, EV_READ | EV_PERSIST, array($this, 'onAccept'), null);
event_base_set($listenerEvent, $this->base);
event_add($listenerEvent, -1);
event_base_loop($this->base);
}
开发者ID:sokal32,项目名称:ranch-cowboy-smoothie-php-draft,代码行数:12,代码来源:ranch_tcp.php
示例12: run
public function run()
{
$this->init();
//建立服务器端Socket
$this->server_sock = $this->create("tcp://{$this->config['host']}:{$this->config['port']}");
//设置事件监听,监听到服务器端socket可读,则有连接请求
\event_set($this->server_event, $this->server_sock, EV_READ | EV_PERSIST, __CLASS__ . '::server_handle_connect', $this);
\event_base_set($this->server_event, $this->base_event);
\event_add($this->server_event);
$this->client->onStart();
\event_base_loop($this->base_event);
}
开发者ID:tempbottle,项目名称:zphp,代码行数:12,代码来源:Php.php
示例13: listen
/**
* Start listening
*/
public function listen()
{
$this->handle_ = stream_socket_server("tcp://{$this->host_}:{$this->port_}", $this->errno_, $this->errstr_);
stream_set_blocking($this->handle_, 0);
// no blocking
$this->base_ = \event_base_new();
$this->serverEvent_ = \event_new();
\event_set($this->serverEvent_, $this->handle_, EV_READ | EV_PERSIST, array($this, 'onConnect'));
\event_base_set($this->serverEvent_, $this->base_);
\event_add($this->serverEvent_);
\event_base_loop($this->base_);
}
开发者ID:kaiyulee,项目名称:thrift-lib-php,代码行数:15,代码来源:TNonblockingServerSocket.php
示例14: run
/**
* 运行服务器程序
* @return unknown_type
*/
function run($setting)
{
$this->init();
//建立服务器端Socket
$this->server_sock = $this->create("tcp://{$this->host}:{$this->port}");
//设置事件监听,监听到服务器端socket可读,则有连接请求
event_set($this->server_event, $this->server_sock, EV_READ | EV_PERSIST, array($this, "event_connect"));
event_base_set($this->server_event, $this->base_event);
event_add($this->server_event);
$this->spawn($setting);
$this->protocol->onStart($this);
event_base_loop($this->base_event);
}
开发者ID:foolkaka,项目名称:soaphp-framework,代码行数:17,代码来源:EventTCP.php
示例15: 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
示例16: listen
public function listen()
{
if (!$this->client_type) {
throw new \Exception('Client type was not defined, please call setClientType() with the type of client (ie \\Beehive\\Clients\\Telnet) before listen()');
}
if (!is_callable($this->read_callback)) {
throw new \Exception('Read callback is not defined with a valid callback, please call setReadCallback() with a valid callback');
}
$this->connection = stream_socket_server('tcp://' . $this->host . ':' . $this->port, $errno, $errstr);
stream_set_blocking($this->connection, 0);
$event = event_new();
event_set($event, $this->connection, EV_READ | EV_PERSIST, [$this, 'addClient'], $this->event_base);
event_base_set($event, $this->event_base);
event_add($event);
event_base_loop($this->event_base);
}
开发者ID:danielmunro,项目名称:beehive,代码行数:16,代码来源:Server.php
示例17: run
/**
* 运行服务器程序
* @return unknown_type
*/
function run($num = 1)
{
//初始化事件系统
if (!$this->protocol instanceof Swoole_TCP_Server_Protocol) {
return error(902);
}
$this->init();
//建立服务器端Socket
$this->server_sock = $this->create("tcp://{$this->host}:{$this->port}");
//设置事件监听,监听到服务器端socket可读,则有连接请求
event_set($this->server_event, $this->server_sock, EV_READ | EV_PERSIST, "sw_server_handle_connect", $this);
event_base_set($this->server_event, $this->base_event);
event_add($this->server_event);
if ($num - 1 > 0) {
sw_spawn($num - 1);
}
$this->protocol->onStart();
event_base_loop($this->base_event);
}
开发者ID:superwmh,项目名称:swoole,代码行数:23,代码来源:EventTCP.class.php
示例18: libevent_serverAction
public function libevent_serverAction()
{
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]);
}
}
$base = event_base_new();
$event = event_new();
$context = new ZMQContext();
$rep = $context->getSocket(ZMQ::SOCKET_REP);
$rep->bind("tcp://127.0.0.1:5555");
$fd = $rep->getSockOpt(ZMQ::SOCKOPT_FD);
event_set($event, $fd, EV_READ | EV_PERSIST, "print_line", array($rep, $base));
event_base_set($event, $base);
event_add($event);
event_base_loop($base);
}
开发者ID:stonegithubs,项目名称:yaf-lib,代码行数:22,代码来源:Zmq.php
示例19: EpollSocketServer
function EpollSocketServer($port)
{
if (!extension_loaded('libevent')) {
self::$errstr = "请先安装libevent扩展库。";
return;
}
if ($port < 1024) {
self::$errstr = "端口号不应小于1024";
return;
}
set_time_limit(0);
$socket_server = stream_socket_server("tcp://0.0.0.0:{$port}", self::$errno, self::$errstr);
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();
}
开发者ID:jumboluo,项目名称:tracking,代码行数:23,代码来源:EpollSocketServer.class.php
示例20: init
public static function init()
{
Daemon::$eventBase = event_base_new();
$args = $_SERVER['argv'];
if (!isset($args[1]) || !isset($args[2])) {
Terminal::drawStr('usage: php xxx.php sArea (start|stop|restart|reload|status)' . "\n");
exit(-1);
}
// todo run multi app in one daemon.
$sArea = $args[1];
$command = $args[2];
$appName = Config::get('socket_server_class', null, true);
Daemon::$runName = $appName;
$runAppInstance = array($appName => $appName);
if ($command == 'start') {
// fork later
self::$pid = posix_getpid();
Debug::log('start');
foreach ($runAppInstance as $appName) {
$obj = new $appName();
}
while (!Daemon::$breakEventLoop) {
event_base_loop(daemon::$eventBase, EVLOOP_ONCE);
// 清空本次写状态数组
gc_collect_cycles();
//daemon::debug('<== evet_base_loop() ending');
}
} elseif ($command == 'stop') {
// cat pid, stop
} elseif ($command == 'status') {
// cat pid, show status
} elseif ($command == 'restart') {
//self::stop();
//self::start();
}
}
开发者ID:ansendu,项目名称:ansio,代码行数:36,代码来源:Daemon.php
注:本文中的event_base_loop函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论