【问题标题】:Laravel Exception explode() expects parameter 2 to be string, array given Illuminate/Queue/Jobs/Job.php:165Laravel Exception explode() 期望参数 2 是字符串,数组给定 Illuminate/Queue/Jobs/Job.php:165
【发布时间】:2017-08-30 09:45:57
【问题描述】:

我正在寻求帮助,我正在使用 RabbitMQ 的队列,我已经安装了 vladimir-yuldashev/laravel-queue-rabbitmq 并且一切正常,但最近我开始遇到一些错误,这真的很奇怪,因为它有时会发生。

它抛出

local.ERROR: 带有消息“explode() 的异常 'ErrorException' 期望参数 2 是字符串,给定数组”在 /home/ubuntu/workspace/frontend/vendor/laravel/framework/src/Illuminate/Queue/Jobs /Job.php:165,

我从Illuminate\Queue\Jobs\Job检查函数parseJob,并转储参数$job,有时它会收到一个类似Illuminate\Queue\CallQueuedHandler@call的字符串,但其他人会收到一个类似的实例

{
    "__PHP_Incomplete_Class_Name":"App\\Jobs\\SendPost",
    "log":[],
    "post": {
        "class":"App\\Models\\Post",
        "id":72
    },
    "start":1491338912.0843,
    "connection":null,
    "queue":"front_send_post_0",
    "delay":null
}

这是我的课:

namespace App\Jobs;

class CheckSendPost implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    const TOTAL_QUEUES = 3;

    public function handle()
    {
        try {
            $posts = Post::getRedyToPost(date('Y-m-d H:i'), null, 0);
            $count = 0;

            Log::info('front_check_send_post: ' . count($posts));

            if (count($posts)) {
                foreach($posts as $post) {   
                        dispatch(
                            (new \App\Jobs\SendPost($post))
                            ->onQueue('front_send_post_' . ($count%self::TOTAL_QUEUES))
                        );

                    $count++;
                }
            }

            dispatch(
                (new \App\Jobs\CheckSendPost)
                ->onQueue('front_check_send_post')
            );
        } catch (\Exception $e) {
            Log::info('ERROR ' . $e->getCode() . ': ' . $e->getMessage());
        }
    }
}


namespace App\Jobs;

class SendPost implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    public $post = null;
    public $start = null;

    public function __construct(Post $post)
    {
        $this->post = $post;
        $this->start = microtime(true);
    }

    public function handle()
    {
        Log::info('Post: '.$this->post->id);

        try {
            $this->post->publish();
            $this->post->setSuccess();
        } catch (\Exception $e) {
            $this->post->setError();
        } finally {
            $this->post->save();
        }

        Log::info(
            date('d-m-Y H:i:s').', '.
            round((microtime(true) - $this->start), 4).' seg, '.
            'Mem '.Helper::formatBytes(memory_get_usage()).', '.
            'Max Mem '.Helper::formatBytes(memory_get_peak_usage())
        );
    }
}

并使用

  • PHP 版本 5.6.29
  • Apache/2.4.7 (Ubuntu)
  • Laravel 5.3

感谢您的帮助。

【问题讨论】:

    标签: laravel queue rabbitmq


    【解决方案1】:

    检查您的命名空间是否都正确。

    __PHP_Incomplete_Class_Name 表示在反序列化时未找到该类。见问题:__PHP_Incomplete_Class_Name wrong

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-01
      • 2018-02-22
      • 2018-11-10
      • 2017-08-08
      相关资源
      最近更新 更多