调试 Laravel 作业

Ian*_*Ian 17 php jobs laravel

我正在尝试在 Laravel 中调试队列上的作业,但没有成功。我想将输出打印到控制台。比如你如何dd()在其他地方使用。

<?php

namespace App\Jobs;

use App\Image;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class ProcessImage implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $image;

    /**
     * Attempt the job a maximum of twice
     *
     * @var int
     */
    public $tries = 2;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(Image $image)
    {

        $this->image = $image;

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // set paths for standard and thumbnail size images

        $image          = public_path("assets" . DIRECTORY_SEPARATOR . $this->image->original);
        $product_id     = $this->image->id;
        $product_path   = public_path("assets" . DIRECTORY_SEPARATOR . "images" . DIRECTORY_SEPARATOR .
            "products" . DIRECTORY_SEPARATOR . $product_id);


        $thumbnail_path = $product_path . DIRECTORY_SEPARATOR . "thumbnail";

        if(!is_dir($product_path))
            mkdir($product_path);

        if(!is_dir($thumbnail_path))
            mkdir($thumbnail_path);

        // Resize and save the standard image

        $standard = \Image::make($image)->resize(450, 450, function($constraint)
        {
            $constraint->aspectRatio();
        })->save($product_path);

        dd($standard);

    }
}
Run Code Online (Sandbox Code Playgroud)

Cri*_*iss 14

1)尝试php artisan queue:restart- 如果您将队列作为守护程序运行,则每次代码更改时都需要重新启动侦听器,因为守护程序将代码加载到内存中。

2)var_dump() dd()并且Log::info()应该在队列中工作。确保您逐步调试 - 在工作开始时登录,然后再降低一点,再降低一点,等等,看看您最后退出的点是什么。

3)检查存储/日志下的laravel.log - 错误应该在某处注销。


yes*_*nik 10

如果你想使用 PHP Storm 编辑 Laravel Job 编辑.env文件:

QUEUE_DRIVER=sync
Run Code Online (Sandbox Code Playgroud)

在函数中放置断点handle()


小智 6

您不需要在控制台上打印它。失败作业的完整描述存储在异常列中。(表名fail_jobs)。
在此输入图像描述


Muh*_*man 3

我所做的是记录需要查看的信息,就像您的情况一样:

\Log::info('Making new directory');
Run Code Online (Sandbox Code Playgroud)

或者

\Log::info('this is new image: ', [$standard]);
Run Code Online (Sandbox Code Playgroud)

等等。只需打开日志信息并查看代码在哪里中断或应该起作用的条件不起作用。