zoukankan      html  css  js  c++  java
  • workerman 的回调函数

    接下来,记录一下workerman 的回调函数

    <?php
    /**
     * Created by PhpStorm.
     * User: zeopean
     * Date: 2016-08-26
     * Time: 17:18
     */
    use WorkermanWorker;
    require_once "../Workerman/Autoloader.php";
    
    //Worker::$daemonize = true ;
    $worker = new Worker("tcp://0.0.0.0:8888");
    
    //设置reloadable
    $worker->reloadable = true;    //不执行重载
    
    //开始进程
    $worker->onWorkerStart = function($worker)
    {
        echo "Worker starting ... 
    ";
    };
    
    //Worker收到reload信号后执行的回调
    $worker->onWorkerReload = function($worker)
    {
        foreach ($worker->connections as $connection)
        {
            $connection->send("worker reloading! 
    ");
        }
    };
    
    //设置Workert停止时的回调函数
    $worker->onWorkerStop = function($worker)
    {
        echo "Worker stopping!!!
    ";
    };
    
    //当有客户端连接时触发的回调函数
    $worker->onConnect = function($connection)
    {
      echo "new connection from ip ".$connection->getRemoteIp();
    };
    
    //当有客户端的连接上有数据发来时触发
    $worker->onMessage = function($connection , $data)
    {
        echo $data;
        $connection -> send("receive success!!");
    };
    
    //当客户端的连接断开时触发,不管连接是如何断开的,只要断开就会触发
    $worker->onClose = function ($connection)
    {
        echo "connection closed! 
    ";
    };
    
    //当连接的应用层发送缓冲区数据全部发送完毕时触发
    $worker->onBufferFull = function($connection)
    {
        echo "bufferFull and do not send ahain
    ";
    };
    
    //onBufferFull 当连接的应用层发送缓冲区满时触发
    $worker -> onBufferDrain = function($connection)
    {
        echo "buffer drain and continue send 
    " ;
    };
    
    // 当worker 发生错误时候调用
    $worker -> onError = function($connection , $code , $msg)
    {
        echo "error $code : $msg 
    ";
    };
    
    Worker::runAll();
    

      

  • 相关阅读:
    CNCC2017中的深度学习与跨媒体智能
    CNCC2017梳理
    Keras Xception Multi loss 细粒度图像分类
    西瓜书概念整理(chapter 1-2)熟悉机器学习术语
    Google机器学习笔记(七)TF.Learn 手写文字识别
    Google机器学习笔记 4-5-6 分类器
    TensorFlow深度学习笔记 Tensorboard入门
    Ubuntu安装与初始配置
    TensorFlow深度学习笔记 循环神经网络实践
    第10组 Alpha冲刺(6/6)
  • 原文地址:https://www.cnblogs.com/zeopean/p/5811355.html
Copyright © 2011-2022 走看看