think-worker如何修改自定义class的pidFile和logFile位置呢?

vicotom168

请问think-worker如何修改SocketServer模式中自定义class的pidFile和logFile位置呢?

config/worker_server.php

<?php
return [
    'worker_class'   => 'app\home\websocket\Worker',
    ];

app/home/websocket/Worker.php

<?php
namespace app\home\websocket;
use Protocols\Http\Request;
use Protocols\Http\Response;
use think\worker\Server;
use Workerman\Connection\TcpConnection;
class Worker extends Server{
    protected $socket = 'Httpd://0.0.0.0:2346';
    protected $option = [
        'count'     => 4,
        'name'      => 'Worker',
    ];
    public function onMessage(TcpConnection $connection,Request $request){
        $connection->send(json_encode($request),true);
    }
954 2 0
2个回答

Tinywan
'pidFile'              => app()->getRuntimePath().'workerman.pid',
'logFile'              => app()->getRuntimePath().'workerman.log',
  • vicotom168 2022-11-12

    写在哪个位置呢?我尝试过写在app/home/websocket/Worker.php里,他提示报错。[think\exception\ErrorException]
    Constant expression contains invalid operations 。它又不能加到config/worker_server.php里,tp手册上面写着:然后在worker_server.php中增加配置参数:

    return [
    'worker_class' => 'app\http\Worker',
    ];
    定义该参数后,其它配置参数均不再有效。

  • Tinywan 2022-11-13

    去看云手册看看

2548a

自定义类一般都继承了他的 Server 类,在 init 函数里面写看看

  • 暂无评论
年代过于久远,无法发表回答
×
🔝