Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5 Laravel 5.2生产中未点火事件_Laravel 5 - Fatal编程技术网

Laravel 5 Laravel 5.2生产中未点火事件

Laravel 5 Laravel 5.2生产中未点火事件,laravel-5,Laravel 5,我有一个laravel活动,在本地运行良好,但在生产中不起作用。我需要它同时向redis和laravel的听众广播。向redis广播的效果与预期一样,但laravel侦听器似乎不起作用 以下是事件的代码: <?php namespace App\Events; use App\Events\Event; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Broadcasting\ShouldBroadcast

我有一个laravel活动,在本地运行良好,但在生产中不起作用。我需要它同时向redis和laravel的听众广播。向redis广播的效果与预期一样,但laravel侦听器似乎不起作用

以下是事件的代码:

<?php

namespace App\Events;

use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class UserAlert extends Event implements ShouldBroadcast
{
    public $email;
    public $type;
    public $message;
    public $data;

    use SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($email, $type, $message, $data = [])
    {
        $this->email = $email;
        $this->type = $type;
        $this->message = $message;
        $this->data = $data;
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['user-alert'];
    }

}

我认为您必须运行队列工作程序来处理队列中的所有作业

尝试php artisan队列:工作

尝试:

$ php artisan clear-compiled
$ php artisan optimize
$ composer install
$ composer dumpautoload
$ php artisan cache:clear
还要确保
eventServiceProvider
中的一切正常。如果您使用排队作业,请检查Kevin Kuiper答案

和你们做的一样,行为也一样:事件被触发,但监听器从未到达。执行这些命令后,工作正常。还使用了一些
dd()
来测试侦听器


来源:我已经使用了和命令的混合。

我运行了所有这些命令,但不幸的是,我仍然有相同的问题,日志上怎么说?在我的laravel日志中没有看到与此相关的任何内容。
<?php

namespace Illuminate\Foundation\Support\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use App\Events\UserAlert;
use App\Listeners\UserAlertListener;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event handler mappings for the application.
     *
     * @var array
     */ 
    protected $listen = [
        'App\Events\UserAlert' => [
            'App\Listeners\UserAlertListener'
        ],
    ];

    /**
     * The subscriber classes to register.
     *
     * @var array
     */
    protected $subscribe = [
        'App\Listeners\UserAlertListener'
    ];

    /**
     * Register the application's event listeners.
     *
     * @param  \Illuminate\Contracts\Events\Dispatcher  $events
     * @return void
     */
    public function boot(DispatcherContract $events)
    {
        foreach ($this->listens() as $event => $listeners) {
            foreach ($listeners as $listener) {
                $events->listen($event, $listener);
            }
        }

        foreach ($this->subscribe as $subscriber) {
            $events->subscribe($subscriber);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function register()
    {
        //
    }

    /**
     * Get the events and handlers.
     *
     * @return array
     */
    public function listens()
    {
        return $this->listen;
    }
}
$ php artisan clear-compiled
$ php artisan optimize
$ composer install
$ composer dumpautoload
$ php artisan cache:clear