我正在尋求幫助,我正在使用隊列與RabbitMQ,我已經安裝了vladimir-yuldashev/laravel-queue-rabbitmq
並且一切正常,但最近我開始發現一些錯誤,這很奇怪,因爲它有時候會發生。Laravel Exception explode()期望參數2是字符串,數組給出Illuminate/Queue/Jobs/Job.php:165
它拋出
local.ERROR: exception 'ErrorException' with message 'explode() expects parameter 2 to be string, array given' in /home/ubuntu/workspace/frontend/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:165,
我檢查功能parseJob從Illuminate\Queue\Jobs\Job
,並轉儲參數$job
,有時收到這類Illuminate\Queue\[email protected]
一個字符串,但其他人收到類似
{
"__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版本29年6月5日
- 的Apache/2.4.7(Ubuntu的)
- Laravel 5.3
感謝您的幫助。