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


PHP swoole_event_add函数代码示例

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


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

示例1: _start

 /**
  * @brief 子进程进入控制调度
  */
 protected function _start()
 {
     swoole_event_add($this->_worker->pipe, function ($pipe) {
         $package = $this->_worker->read();
         $this->_stats($package);
     });
 }
开发者ID:eyehere,项目名称:aha,代码行数:10,代码来源:Stats.php

示例2: start

 /**
  * @brief 启动子进程
  * @param \swoole_process $worker
  */
 public function start(\swoole_process $worker)
 {
     $this->_worker = $worker;
     swoole_event_add($worker->pipe, function ($pipe) use($worker) {
         echo $worker->read() . PHP_EOL;
     });
     $this->worker();
 }
开发者ID:vucms,项目名称:aha,代码行数:12,代码来源:Asyncworker.php

示例3: _initPipeEvents

 protected function _initPipeEvents($process, $workerType)
 {
     \Daemon\Library\Ipc\Shared::setCurrentTaskTable($process->pid, array('taskNum' => 0, 'workerType' => $workerType));
     $objMaster = \Daemon\Process\Master::getInstance();
     swoole_event_add($process->pipe, function ($pipe) use($process, $objMaster) {
         $objMaster->dispatch($process);
     });
 }
开发者ID:eyehere,项目名称:aha,代码行数:8,代码来源:Manager.php

示例4: init

 function init()
 {
     $this->serv->on('WorkerStart', function (\swoole_server $serv, $worker_id) {
         //每1分钟向服务器上报
         $serv->tick(60000, [$this, 'onTimer']);
         swoole_event_add($this->centerSocket->sock, [$this, 'onPacket']);
     });
     $this->log(__CLASS__ . '-' . self::VERSION . ' is running.');
 }
开发者ID:FrankWebDev,项目名称:node-agent,代码行数:9,代码来源:Node.php

示例5: __construct

 public function __construct()
 {
     $this->process = new swoole_process(array($this, 'run'), false, true);
     //$this->process->daemon(true,true);
     $this->process->start();
     swoole_event_add($this->process->pipe, function ($pipe) {
         $data = $this->process->read();
         echo "RECV: " . $data . PHP_EOL;
     });
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:10,代码来源:base_process.php

示例6: createConnection

 /**
  * create mysql connection
  */
 protected function createConnection()
 {
     $config = $this->config;
     $db = new \mysqli();
     $db->connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     $db_sock = swoole_get_mysqli_sock($db);
     swoole_event_add($db_sock, array($this, 'onSQLReady'));
     $this->idle_pool[] = array('object' => $db, 'socket' => $db_sock);
     $this->connection_num++;
 }
开发者ID:silentred,项目名称:learning-path,代码行数:13,代码来源:MySQL.php

示例7: onConnect

 public function onConnect($client)
 {
     fwrite(STDOUT, "Enter Msg:");
     swoole_event_add(STDIN, function ($fp) {
         global $client;
         fwrite(STDOUT, "Enter Msg:");
         $msg = trim(fgets(STDIN));
         $client->send($msg);
     });
 }
开发者ID:zhangchao1,项目名称:php_design,代码行数:10,代码来源:websocket_client.php

示例8: onStart

 function onStart($serv)
 {
     $this->serv = $serv;
     for ($i = 0; $i < $this->pool_size; $i++) {
         $db = new mysqli();
         $db->connect('172.16.1.19', 'test', 'test', '1188test');
         $db_sock = swoole_get_mysqli_sock($db);
         swoole_event_add($db_sock, array($this, 'onSQLReady'));
         $this->idle_pool[] = array('mysqli' => $db, 'db_sock' => $db_sock, 'fd' => 0);
     }
     echo "Server: start.Swoole version is [" . SWOOLE_VERSION . "]\n";
 }
开发者ID:silentred,项目名称:learning-path,代码行数:12,代码来源:mysql_proxy_server.php

示例9: task_run

 public function task_run($worker)
 {
     swoole_event_add($worker->pipe, function ($pipe) use($worker) {
         $data = $worker->read();
         var_dump($worker->pid . ": " . $data);
         if ($data == 'exit') {
             $worker->exit();
             exit;
         }
         sleep(5);
         $worker->write("" . $worker->pid);
     });
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:13,代码来源:dynamic.php

示例10: callback_function

function callback_function(swoole_process $worker)
{
    $GLOBALS['worker'] = $worker;
    swoole_event_add($worker->pipe, function ($pipe) {
        $worker = $GLOBALS['worker'];
        $recv = $worker->read();
        if ($recv) {
            $data = call_user_func_array('dosomething', [json_decode($recv, true)]);
            $worker->write($data);
        } else {
            $worker->write('');
        }
    });
}
开发者ID:xingcuntian,项目名称:ssos,代码行数:14,代码来源:test_process.php

示例11: onConnect

 public function onConnect($cli)
 {
     fwrite(STDOUT, "Enter your name: ");
     $msg = trim(fgets(STDIN));
     $data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'online', 'name' => $msg));
     $data = pack("Na*", strlen($data), $data);
     $cli->send($data);
     swoole_event_add(STDIN, function ($fp) {
         global $cli;
         $msg = trim(fgets(STDIN));
         $data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'send', 'sendto' => $this->channel, 'msg' => $msg));
         $data = pack("Na*", strlen($data), $data);
         $cli->send($data);
     });
 }
开发者ID:ppker,项目名称:swoole-doc,代码行数:15,代码来源:chatroom.php

示例12: callback_function_async

function callback_function_async(swoole_process $worker)
{
    echo "Worker: start. PID=" . $worker->pid . "\n";
    //recv data from master
    $GLOBALS['worker'] = $worker;
    swoole_event_add($worker->pipe, function ($pipe) {
        $worker = $GLOBALS['worker'];
        $recv = $worker->read();
        echo "From Master: {$recv}\n";
        //send data to master
        $worker->write("hello master\n");
        sleep(5);
        $worker->exit(0);
    });
}
开发者ID:vkey24,项目名称:crazy-grab,代码行数:15,代码来源:worker.php

示例13: child_async

function child_async(swoole_process $worker)
{
    //echo "Worker: start. PID=".$worker->pid."\n";
    //recv data from master
    $GLOBALS['worker'] = $worker;
    global $argv;
    $worker->name("{$argv[0]}: worker");
    swoole_process::signal(SIGTERM, function ($signal_num) use($worker) {
        echo "signal call = {$signal_num}, #{$worker->pid}\n";
    });
    swoole_event_add($worker->pipe, function ($pipe) use($worker) {
        $recv = $worker->read();
        echo "From Master: {$recv}\n";
        $worker->write("hello master\n");
    });
}
开发者ID:stonegithubs,项目名称:swoole-game,代码行数:16,代码来源:server.php

示例14: __construct

 public function __construct()
 {
     $fp = stream_socket_client("tcp://127.0.0.1:9504", $code, $msg, 3);
     $http_request = "GET /index.html HTTP/1.1\r\n\r\n";
     fwrite($fp, $http_request);
     swoole_event_add($fp, function ($fp) {
         echo fread($fp, 8192);
         swoole_event_del($fp);
         fclose($fp);
     });
     swoole_timer_after(2000, function () {
         echo "2000ms timeout\n";
     });
     swoole_timer_tick(1000, function () {
         echo "1000ms interval\n";
     });
 }
开发者ID:nosun,项目名称:yaf,代码行数:17,代码来源:async.php

示例15: onStart

 public function onStart($server)
 {
     $pro_vs = $this->process;
     $server = $this->server;
     $application_vm = $this->application;
     swoole_event_add($pro_vs->pipe, function ($pipe) use($pro_vs, $server, $application_vm) {
         $str = $pro_vs->read();
         ob_start();
         $application_vm->execute(array('swoole_socket', 'getfd'), 'vmstat');
         $result = ob_get_contents();
         ob_end_clean();
         $result_fd = json_decode($result, true);
         foreach ($result_fd as $id => $fd) {
             $server->push($fd, $str);
         }
     });
 }
开发者ID:qieangel2013,项目名称:zys,代码行数:17,代码来源:VmStatServer.php


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