Laravel 5命令不返回数据

蜡笔

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

家庭控制器

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输入命令-那么当您运行它时,什么都不会立即发生,因此它返回null。同时,该命令将在队列处理系统中分别在后台运行。

如果您需要立即答复-只需在不排队的情况下运行该命令即可。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章