swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

App::$server return null #122

Closed jianhuihi closed 6 years ago

jianhuihi commented 6 years ago

App::$server return null

inhere commented 6 years ago

能提供更多的相关信息吗? 怎么出现的? 运行环境?

jianhuihi commented 6 years ago
sudo php bin/swoft rpc:start
                    Information Panel                     
**********************************************************
* tcp | Host: 0.0.0.0, port: 8099, Model: 3, type: 1
**********************************************************

然后我在app/commands

<?php
namespace App\Commands;
use Swoft\App;
use Swoft\Console\Bean\Annotation\Command;
use Swoft\Console\Bean\Annotation\Mapping;
use Swoft\Console\Input\Input;
use Swoft\Console\Output\Output;
use Swoft\Core\Coroutine;
use Swoft\Log\Log;
use Swoft\Task\Task;
class TestCommand {

    public function test(Input $input, Output $output) {
          var_dump(App::$server);exit;
        }
}

然后命令行模式执行 sudo php bin/swoft test:test

jianhuihi commented 6 years ago

/ | ____ / | | \ \ \ /\ / / | || | ) \ V V / () | | | |/ _/_/ __/|| __|

swoft: 0.2.2, php: 7.1.14, swoole: 2.1.0

stelin commented 6 years ago

console启动没有初始化App::$server,你使用场景是什么

jianhuihi commented 6 years ago

想在命令行投递task 能在console启动初始化App::$server么?

stelin commented 6 years ago

可以这样投递任务,暂时还没有封装 https://wiki.swoole.com/wiki/page/212.html

huangzhhui commented 6 years ago

@jianhuihi 你是想通过Command往正在运行的Server里面投递Task给TaskWorker消费吗?

stelin commented 6 years ago

@jianhuihi 已支持,任务投递,https://doc.swoft.org/master/zh-CN/console/task.html