zoukankan      html  css  js  c++  java
  • workerman 的属性

    <?php
    /**
     * Created by PhpStorm.
     * User: zeopean
     * Date: 2016-08-26
     * Time: 16:35
     */
    
    use WorkermanWorker;
    use WorkermanLibTimer;
    require_once "../Workerman/Autoloader.php";
    
    Worker::$daemonize = true;      //该进程为 守护进程
    
    Worker::$stdoutFile = '/tmp/worker.log';    //打印输出到指定文件
    
    Worker::$pidFile = '/tmp/workerman.pid';//设置WorkerMan进程的pid文件路径 不建议使用
    
    Worker::$logFile = '/tmp/worker1.log';  //设置workerman日志文件位置
    
    $worker = new Worker("tcp://0.0.0.0:8585");
    $worker -> count = 4;                           // 设置进程数
    $worker -> name = 'myWorker-zp';                //设置进程名字
    $worker -> user = 'www';                        //设置运行用户
    
    $worker -> reloadable = true ;                  //设置此实例收到reload信号后是否reload重启
    
    $worker -> transport  = 'udp';                  //设置实例使用的传输协议 tcp | udp
    
    $worker -> onWorkerStart = function($worker){   //启动进程
        if($worker -> id === 0)
        {
            Timer::add(1 , function(){              //使用定时器
                $time = time();
    
                echo "worker id 为0 时,打印!======> $time 
    ";
            });
    
            Timer::add(10 , function() use ($worker){
                // 遍历当前进程所有的客户端连接,发送当前服务器的时间
               foreach($worker->connections as $connection)
               {
                    $connection -> send(time());
               }
            });
        }
    };
    
    Worker::runAll();
    

      

    2.创建一个workerman 进程实例

      php demo.pro.php start

      php demo.pro.php stop

      php demo.pro.php reload

    3.在新的窗口进行连接

      telnet 127.0.0.1 8585

  • 相关阅读:
    Visual C++ in Visual Studio 2015
    Paxos
    dtrace
    性能测试应该怎么做?
    CLREX
    Header Field Definitions Accept-Encoding
    汇编跟逆向工程
    Optimize Managed Code For Multi-Core Machines
    Improve Scalability With New Thread Pool APIs
    CLR thread pool
  • 原文地址:https://www.cnblogs.com/zeopean/p/workerman.html
Copyright © 2011-2022 走看看