Php Laravel 5排队命令

Php Laravel 5排队命令,php,laravel,command,queue,laravel-5,Php,Laravel,Command,Queue,Laravel 5,我正在使用Laravel5制作一个应用程序,目前我有一个小问题(我希望如此)。 因此,我编写了一个命令,实现了如下所示的ShouldBeQueued: class ImportDataCommand extends Command implements SelfHandling,ShouldBeQueued { use InteractsWithQueue, SerializesModels; public $filePath; /** * Create

我正在使用Laravel5制作一个应用程序,目前我有一个小问题(我希望如此)。 因此,我编写了一个命令,实现了如下所示的ShouldBeQueued:

class ImportDataCommand extends Command implements SelfHandling,ShouldBeQueued {


    use InteractsWithQueue, SerializesModels;

    public $filePath;

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct($filePath)
    {
        $this->filePath = $filePath;
        Log::info('queued shit from command contructor and i have this destinationPath => '.$filePath);//working
        echo "contructor ".$this->filePath;

    }

    /**
     * Execute the command.
     *
     * @return void
     */
    public function handle()
    {


        $destinationPath = storage_path().'/app/gtfs/';


        $zip = new ZipArchive;
        echo "handle ".$this->filePath;
        /*$res = $zip->open($destinationPath.$this->filePath);
        if ($res === TRUE) {
            $zip->extractTo($destinationPath.'extracted/');
            $zip->close();
            echo 'done';

        } else {

            echo 'fail';

        }*/
    }

}
我这样称呼它:

$bus->dispatch(new ImportDataCommand($fileName));

我的问题是,当在队列中执行命令时(顺便说一句,我使用的是
beanstalkd
),它会抛出一个异常,因为没有设置
filePath
,我想我已经理解了为什么会发生这种情况,当我使用变量将该命令发送到
busdpatcher
上的队列时,会实例化该命令,但当在队列侧调用
handle()
时,它不会发送该命令。有什么建议吗?

您在构造函数中分配
$this->filePath
,然后在
handle()
方法中重写它。

最后我找到了兔子:我完全忘记了每次尝试刷新所有作业,所以我不知道为什么,但它会干扰命令(我已将流浪者机器重新启动到,但我认为这不会影响任何事情)。

很抱歉,现在已修复了一个错误,如果我完全按照现在的方式运行,我无法访问空属性[Symfony\Component\Debug\Exception\FatalErrorException]当我告诉artisan运行排队作业时php artisan队列:workecho“handle”.$this->filePath;如果在
echo“handle”之前分配了某个内容,是否也会出现错误。$this->filePath;