平滑重启使PHP文件有效

在 Swoole 文档中有这么一说明
平滑重启只对onWorkerStart或onReceive等在Worker进程中include/require的PHP文件有效,Server启动前就已经include/require的PHP文件,不能通过平滑重启重新加载 "

让我们来测试一下:
# php http_server.php
WorkerStart  
WorkerStart 

访问  http:// www.test-yy.com
页面内容输出 "   hello Swoole test "

命令行中输出:
Test1
request 100 Test1

当我们将
test.php
test_request.php
代码中的 Test1 替换成 Test2 时

访问  http:// www.test-yy.com
命令行中输出:
Test1
request 88 Test2

# ps -ef | grep php
# kill -USR1 8155        // 平滑重启, 8155(主进程/管理进程 id

再次访问  http:// www.test-yy.com
命令行中输出:
Test1
request 88 Test2

以上结果说明了  include/require ,再 Server 启动前载入的PHP文件,不能通过平滑重启重新加载

测试代码:
http_server.php
<?php
echo 'shell start';
define('__ROOT__', realpath('.'));
include __ROOT__.'/test.php';

$http = new swoole_http_server("127.0.0.1", 9501);
$http->set([
    'worker_num'=>2,
    'max_request'=>50
]);

$http->on('WorkerStart', function ($serv, $worker_id){
    echo "WorkerStart \n";
});

$http->on('request', function ($request, $response) {
    getTest();
    include __ROOT__.'/test_request.php';
    $response->header("Content-Type", "text/html; charset=utf-8");
    $response->end(getTplContent());
});
$http->start();

function getTplContent() {
    return "hello Swoole test \n";
}
?>

test.php
<?php
function getTest() {
    echo "Test1 \n";
}
?>

test_request.php
<?php
echo 'request '.rand(1,100)."Test1 \n";
?>

nginx 配置
test.conf
server {
listen      80;
server_name   www.test-yy.com;
...
location ~\.php$ {
                proxy_http_version 1.1;
                proxy_set_header Connection "keep-alive";
                proxy_set_header X-Real-IP $remote_addr;
                proxy_pass http://127.0.0.1:9501;
        }

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值