Laravel 5 命令不返回数据

Laravel 5 Command not Returning Data

我正在尝试使用命令以便将它们排队,因为一堆请求需要 30-90 秒才能完成。唯一的问题是命令没有像我希望的那样将数据返回到我的控制器,相反,我得到的只是一个方便的(讽刺)"null"。这是我文件中的一些代码片段,感谢您的帮助!

家庭控制器

class HomeController extends Controller {

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    //
}

/**
 * Show the application dashboard to the user.
 *
 * @return Response
 */
public function index()
{
    var_dump($this->dispatch(new \App\Commands\GetFeedCommand("http://alerts.weather.gov/cap/us.atom")));
}

GetFeedController

use App\Commands\Command;

use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
use GuzzleHttp\Client;

class GetFeedCommand extends Command implements ShouldBeQueued {

    use InteractsWithQueue, SerializesModels;

    public $guzzle;
    public $uri;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct($uri)
    {
        $this->guzzle = new Client;
        $this->uri = $uri;
    }

}

GetFeedControllerHelper

use App\Commands\GetFeedCommand;

use Illuminate\Queue\InteractsWithQueue;

class GetFeedCommandHandler {

    /**
     * Create the command handler.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the command.
     *
     * @param  GetFeedCommand  $command
     * @return void
     */
    public function handle(GetFeedCommand $command)
    {
        return $command->guzzle->get($command->uri)->xml();
    }

}

如有任何帮助,我们将不胜感激!谢谢!

没错。

如果您 queue 命令 - 那么当您 运行 它不会立即发生任何事情,因此它 returns 无效。同时该命令将运行在您的队列处理系统的后台单独运行。

如果您需要立即回复 - 那么只需 运行 没有队列的命令。