swoole为什么不建议使用static和global

$http = new swoole_http_server("0.0.0.0", 9501);
$http->on("request", function ($request, $response) {
    static $i;
    $i++;
    var_dump($i);
    $response->end($i);

});

$http->start();

  

http://192.168.33.10:9501/  访问 

你会发现 常驻进程后静态变量不会释放,每个用户访问一次,就加一次。

 

[root@localhost swoole]# php time.php
^[[15~int(1)
int(2)
int(3)
int(4)
int(5)
int(6)
int(7)
int(8)
int(9)
int(10)
int(11)
int(12)

  

posted @ 2020-07-21 08:02  brady-wang  阅读(1401)  评论(0编辑  收藏  举报