本文整理汇总了PHP中event_base_new函数的典型用法代码示例。如果您正苦于以下问题:PHP event_base_new函数的具体用法?PHP event_base_new怎么用?PHP event_base_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了event_base_new函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->base = event_base_new();
$this->callback = $this->createLibeventCallback();
$this->timersGc = new \SplQueue();
$this->timersGc->setIteratorMode(\SplQueue::IT_MODE_DELETE);
}
开发者ID:jxw7733,项目名称:zphpdemo,代码行数:7,代码来源:EVLoop.php
示例2: __construct
public function __construct()
{
// @codeCoverageIgnoreStart
if (!\extension_loaded("libevent")) {
throw new \RuntimeException("The pecl libevent extension is required to use " . __CLASS__);
}
// @codeCoverageIgnoreEnd
$this->base = \event_base_new();
$this->keepAliveBase = \event_base_new();
/**
* Prior to PHP7 we can't cancel closure watchers inside their own callbacks
* because PHP will fatal. In legacy versions we schedule manual GC workarounds.
*
* @link https://bugs.php.net/bug.php?id=62452
*/
if (PHP_MAJOR_VERSION < 7) {
$this->gcEvent = event_new();
\event_timer_set($this->gcEvent, function () {
$this->garbage = [];
$this->isGcScheduled = false;
\event_del($this->gcEvent);
});
\event_base_set($this->gcEvent, $this->keepAliveBase);
}
$this->onCoroutineResolution = function ($e = null, $r = null) {
if ($e) {
$this->onCallbackError($e);
}
};
}
开发者ID:nimmen,项目名称:amp,代码行数:30,代码来源:LibeventReactor.php
示例3: __construct
/**
* Construct new event base
*
* @see event_base_new
* @link http://www.php.net/manual/function.event-base-new.php
* @param int $priority
* @throws EventException
*/
public function __construct($priority = self::DEFAULT_PRIORITY)
{
if (false === ($this->resource = event_base_new())) {
throw $this->exception('Could not create event base resourse (event_base_new).');
}
$this->setPriority($priority);
}
开发者ID:omgnull,项目名称:php-libevent,代码行数:15,代码来源:EventBase.php
示例4: 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
示例5: __construct
/**
* Creates the main event loop
*
* @param int $priorities The number of different priorities
*/
public function __construct($priorities = null)
{
$this->resource = event_base_new();
if (!is_null($priorities)) {
event_base_priority_init($this->resource, $priorities);
}
}
开发者ID:ansendu,项目名称:phpLibEventWrapper,代码行数:12,代码来源:Base.php
示例6: getBase
public static function getBase()
{
if (!self::$globalBase) {
self::$globalBase = event_base_new();
}
return self::$globalBase;
}
开发者ID:hinathan,项目名称:edges-php,代码行数:7,代码来源:Emitter.php
示例7: __construct
public function __construct($addr = '127.0.0.1', $port = 8305, $listenQueue = 512)
{
if (is_null(self::$_logger)) {
self::$_logger = \Zopt\Base\Logger::getLogger(__CLASS__);
}
if (!extension_loaded('libevent')) {
self::$_logger->crit('FATAL: Please firstly install libevent extension.');
die;
}
$this->_addr = $addr;
$this->_port = $port;
$this->_listenQueue = $listenQueue;
$this->_started = FALSE;
$this->_sock = NULL;
// Init the event machine using libevent c extension
$this->_listenEvent = NULL;
$this->_eventBase = event_base_new();
$this->_streams = array();
// Register signal handlers
$this->_signalEvents = array();
foreach (array(SIGTERM, SIGHUP, SIGINT, SIGQUIT) as $signo) {
$event = event_new();
event_set($event, $signo, EV_SIGNAL | EV_PERSIST, array($this, 'handleSignalEvent'), $signo);
event_base_set($event, $this->_eventBase);
event_add($event);
$this->_signalEvents[$signo] = $event;
}
}
开发者ID:BGCX261,项目名称:zoptimizer-svn-to-git,代码行数:28,代码来源:server.php
示例8: __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
示例9: 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
示例10: 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
示例11: __construct
/**
* LeBase constructor.
*/
public function __construct()
{
$this->handle = event_base_new();
if ($this->handle === false) {
throw new \RuntimeException('Can not initialize libevent.');
}
}
开发者ID:edefimov,项目名称:async-sockets,代码行数:10,代码来源:LeBase.php
示例12: initialize
/**
* Normally this would go into the __construct() function but it's split out into its own
* method because we also have to initialize() when calling afterFork().
*/
private function initialize()
{
$this->base = event_base_new();
$this->gcEvent = event_new();
event_timer_set($this->gcEvent, [$this, 'collectGarbage']);
event_base_set($this->gcEvent, $this->base);
}
开发者ID:medehghani,项目名称:alert,代码行数:11,代码来源:LibeventReactor.php
示例13: 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
示例14: 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
示例15: __construct
public function __construct()
{
$this->eventBase = event_base_new();
$this->nextTickQueue = new NextTickQueue($this);
$this->timerEvents = new SplObjectStorage();
$this->createTimerCallback();
$this->createStreamCallback();
}
开发者ID:nrk,项目名称:react,代码行数:8,代码来源:LibEventLoop.php
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: __construct
public function __construct($address, $port)
{
$this->base = event_base_new();
$this->event = event_new();
Logger::getInstance()->outString("Create new socket for " . $address . ":" . $port);
$errno = 0;
$errstr = '';
$socket = stream_socket_server('tcp://' . $address . ':' . $port, $errno, $errstr);
stream_set_blocking($socket, 0);
event_set($this->event, $socket, EV_READ | EV_PERSIST, array($this, 'accept'), $this->base);
event_base_set($this->event, $this->base);
event_add($this->event);
$this->onLoad();
}
开发者ID:lan143,项目名称:battleship,代码行数:14,代码来源:Listener.php
注:本文中的event_base_new函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论