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

PHP swoole_event_add函数代码示例

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

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



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


示例16: onConnect

 public function onConnect($cli)
 {
     $this->client->sendHeader($this->client->createHeader());
     fwrite(STDOUT, "Enter your name: ");
     $msg = trim(fgets(STDIN));
     $data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'online', 'name' => $msg));
     $this->client->send($data);
     swoole_event_add(STDIN, function ($fp) {
         $msg = trim(fgets(STDIN));
         if ($msg == 'exit') {
             $data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'offline', 'name' => $msg));
             $this->client->send($data);
             exit;
         }
         $data = json_encode(array('json' => 'Chat', 'ctrl' => 'Chat', 'method' => 'send', 'sendto' => $this->channel, 'msg' => $msg));
         $this->client->send($data);
     });
 }
开发者ID:jinchunguang,项目名称:swoole-doc,代码行数:18,代码来源:client.php


示例17: create_process

 /**
  * 创建一个子进程
  * @param $task
  */
 public function create_process($id, $task)
 {
     $this->task = $task;
     $process = new swoole_process(array($this, "run"));
     if (!($pid = $process->start())) {
     }
     //记录当前任务
     Crontab::$task_list[$pid] = array("start" => microtime(true), "id" => $id, "task" => $task, "type" => "crontab", "process" => $process);
     swoole_event_add($process->pipe, function ($pipe) use($process) {
         $task = $process->read();
         list($pid, $sec) = explode(",", $task);
         if (isset(Crontab::$task_list[$pid])) {
             $tasklist = Crontab::$task_list[$pid];
             Crontab::$delay[time() + $sec] = $tasklist["task"];
             $process->write($task);
         }
     });
 }
开发者ID:noikiy,项目名称:swoole-crontab,代码行数:22,代码来源:Process.class.php


示例18: onConnect

 public function onConnect($cli)
 {
     fwrite(STDOUT, "Enter cmd:");
     swoole_event_add(STDIN, function ($fp) {
         global $cli;
         $cmd = trim(fgets(STDIN));
         if (is_numeric($cmd)) {
             $filename = "Test.txt";
             $i = intval($cmd);
             if ($i == Client::UPLOAD) {
                 $cli->sendfile($filename);
             } else {
                 if ($i == Client::DOWNLOAD) {
                     $cli->send(Client::DOWNLOAD, $filename);
                 }
             }
         }
     });
 }
开发者ID:hytzxd,项目名称:swoole-doc,代码行数:19,代码来源:swoole_sendfile_client.php


示例19: send

 /**
  * [send 兼容Base类封装的send方法,调度器可以不感知client类型]
  * @param  [type] $callback [description]
  * @return [type]           [description]
  */
 public function send(callable $callback)
 {
     if (!isset($this->db)) {
         echo " db not init \n";
         //TODO do callback function to task
         return;
     }
     //TODO conf check
     $config = $this->conf;
     $this->callback = $callback;
     $this->calltime = microtime(true);
     $this->key = md5($this->calltime . $config['host'] . $config['port'] . rand(0, 10000));
     $this->db->connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     if (!empty($config['charset'])) {
         $this->db->set_charset($config['charset']);
     }
     $db_sock = swoole_get_mysqli_sock($this->db);
     swoole_event_add($db_sock, array($this, 'onSqlReady'));
     $this->doQuery($this->sql);
 }
开发者ID:delphinBlue,项目名称:tsf,代码行数:25,代码来源:MYSQL.php


示例20: __construct

 /**
  * @param $serverPid
  * @throws NotFound
  */
 function __construct($serverPid)
 {
     $this->pid = $serverPid;
     if (posix_kill($serverPid, 0) === false) {
         throw new NotFound("Process#{$serverPid} not found.");
     }
     $this->inotify = inotify_init();
     $this->events = IN_MODIFY | IN_DELETE | IN_CREATE | IN_MOVE;
     swoole_event_add($this->inotify, function ($ifd) {
         $events = inotify_read($this->inotify);
         if (!$events) {
             return;
         }
         var_dump($events);
         foreach ($events as $ev) {
             if ($ev['mask'] == IN_IGNORED) {
                 continue;
             } else {
                 if ($ev['mask'] == IN_CREATE or $ev['mask'] == IN_DELETE or $ev['mask'] == IN_MODIFY or $ev['mask'] == IN_MOVED_TO or $ev['mask'] == IN_MOVED_FROM) {
                     $fileType = strstr($ev['name'], '.');
                     //非重启类型
                     if (!isset($this->reloadFileTypes[$fileType])) {
                         continue;
                     }
                 }
             }
             //正在reload,不再接受任何事件,冻结10秒
             if (!$this->reloading) {
                 $this->putLog("after 10 seconds reload the server");
                 //有事件发生了,进行重启
                 swoole_timer_after($this->afterNSeconds * 1000, array($this, 'reload'));
                 $this->reloading = true;
             }
         }
     });
 }
开发者ID:jonny77,项目名称:auto_reload,代码行数:40,代码来源:AutoReload.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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