新手请教这是为什么

chen

控制器代码

app/controller/Index.php

class Index
{
    protected $count;

    public function index(Request $request)
    {
        $this->count++;
        return response('count:' . $this->count);
    }
}

配置文件代码

config/server.php

return [
    // ...
    'count' => 1,
    // ...
];

测试过程

先打开浏览器,输入http://127.0.0.1:8787/ 输出 1
执行 ab -n 5000 -c 100 -k http://127.0.0.1:8787/
再刷新页面,输出 5002

到这里一切正常


如果我把配置文件 config/server.php 里的 count 配置项值改为 2,执行 php start.php restart,再执行一遍上面的测试过程,最终输出的结果是 2577,请问是为什么啊

1073 2 0
2个回答

Tinywan

你操作系统是啥?

walkor

进程间变量是隔离的,不共享。
2个进程,每个进程有自己的count 变量,当你用浏览器访问某个进程时,显示的是当前进程count的值

年代过于久远,无法发表回答
🔝