直接运行正常,打包二进制后运行报错,日志不可写

isle

问题描述

在webman中自定义命令,是用workman启动监听之后,会自动生成workman日志,但是在打包二进制后,文件写入失败。

程序代码

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $name = $input->getArgument('name');
        $output->writeln('Hello log_server');
        $tcp_worker = new Worker('tcp://0.0.0.0:11101');
        $tcp_worker->onWorkerStart = function ($tcp_worker) {
            $udp_worker = new Worker('udp://0.0.0.0:11100');
            $udp_worker->onMessage = function ($udp_connection, $data) use ($tcp_worker) {
                $wmService = new WmService();
                $x = 1;
                HELL:
                $len = unpack("x{$x}/C", $data)[1];
                if ($len > 127) {
                    $len = 32768 ^ unpack("x{$x}/n", $data)[1];
                    $x = $x + 1;
                }
                $l = $x + 5;
                $len1 = unpack("x{$l}/C", $data)[1];
                if ($len1 > 127) {
                    $len1 = 32768 ^ unpack("x{$l}/n", $data)[1];
                    $l = $l + 1;
                }
                $l = $l + 1;
                $data1 = unpack("x{$l}/a{$len1}", $data)[1];;
                $data1 = iconv('gb2312', 'utf-8', ($data1));

                $x = $len + $x + 2;
                if ($x < strlen($data)) {
                    goto HELL;
                }
                Log::info($data1);
                $msg_data = $wmService->getGameLogSwoole($data1, date('Y-m-d H:i:s'));
                if (!empty($msg_data)) {
                    $wmService->gameLogsSwooleInsert($msg_data);
                }
            };
            $udp_worker->listen();
        };
        Worker::runAll();
        $output->writeln('运行成功');
        return self::SUCCESS;
    }

报错信息

[root@VM-0-12-centos build]# ./webman.bin log_server start
Hello log_server
Workerman[./webman.bin] start in DEBUG mode
file_put_contents(phar:///home/www/webman/build/webman.bin/vendor/workerman/workerman/../workerman.log): Failed to open stream: phar error: open mode append not supported in file phar:///home/www/webman/build/webman.bin/vendor/workerman/workerman/Worker.php on line 2226
fopen(phar:///home/www/webman/build/webman.bin/vendor/workerman/workerman/../_home_www_webman_build_webman.bin.pid.lock): Failed to open stream: phar error: open mode append not supported in file phar:///home/www/webman/build/webman.bin/vendor/workerman/workerman/Worker.php on line 642
file_put_contents(phar:///home/www/webman/build/webman.bin/vendor/workerman/workerman/../_home_www_webman_build_webman.bin.pid): Failed to open stream: phar error: write operations disabled by the php.ini setting phar.readonly in file phar:///home/www/webman/build/webman.bin/vendor/workerman/workerman/Worker.php on line 1337

In Worker.php line 1338:

  can not save pid to phar:///home/www/webman/build/webman.bin/vendor/workerman/  
  workerman/../_home_www_webman_build_webman.bin.pid                              

log_server [<name>]

截图报错信息里报错文件相关代码

截图

操作系统及workerman/webman等框架组件具体版本

centos6.9,php版本7.2,workerman/webman是直接composer安装的
workerman/workerman :v4.1.10
workerman/webman-framework :v1.5.6
webman/think-orm:v1.1.1
webman/console:v1.2.35

1016 1 0
1个回答

walkor 打赏

有可能你的配置文件config/server.php缺少了pid_file status_file stdout_file log_file设置,参考下面配置设置下,设置到 runtime_path() 目录下

return [
    'listen' => 'http://0.0.0.0:8787',
    'transport' => 'tcp',
    'context' => [],
    'name' => 'webman',
    'count' => cpu_count() * 4,
    'user' => '',
    'group' => '',
    'reusePort' => false,
    'event_loop' => '',
    'stop_timeout' => 2,
    'pid_file' => runtime_path() . '/webman.pid',
    'status_file' => runtime_path() . '/webman.status',
    'stdout_file' => runtime_path() . '/logs/stdout.log',
    'log_file' => runtime_path() . '/logs/workerman.log',
    'max_package_size' => 25 * 1024 * 1024
];
  • isle 2023-06-25

    感谢大佬,我是设置了,依然是这个问题,但是我已经使用 webman的 “自定义进程” 来实现了功能了,目前运行正常,非常感谢。

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