brentxscholl's avatar

Laravel Debugbar Alternative for Scheduled Job Development

Larvel Debugbar works get to see performance when optimizing your controllers, livewire components, etc. However my app has a lot of scheduled jobs. Checking performance and optimizing is a bit trickier without being able to use a tool like Laravel Debugbar. I'm wondering if there are any solutions out there as simple as debugbar?

I'm aware of xdebug and blackfire.io, but I've found these tools to be a bit cumbersome to set up and overwhelming.

I currently use a command or a test to dispatch the job, and log or dd() things such as memory_usage() or query results, etc. but this seems a bit clunky and not a very good way to see number of queries, number of models, run time, etc. like you can see with debugbar.

Does anyone have any advise on a work flow when developing and optimizing Laravel jobs?

0 likes
2 replies
LaryAI's avatar
Level 58

One alternative to Laravel Debugbar for monitoring performance of scheduled jobs in Laravel is to use the Telescope package. Telescope is a debugging assistant for Laravel applications that provides a clean and elegant interface for monitoring various aspects of your application's performance.

To install Telescope, you can follow these steps:

  1. Install the package via Composer:
composer require laravel/telescope
  1. Publish the Telescope assets and configuration file:
php artisan telescope:install
  1. Migrate the Telescope tables to your database:
php artisan migrate
  1. Optionally, you can configure Telescope to only be available in non-production environments by adding the following code to your app/Providers/TelescopeServiceProvider.php file:
public function register()
{
    if ($this->app->isLocal()) {
        $this->registerTelescope();
    }
}

Once Telescope is installed and configured, you can access it by visiting the /telescope route in your application. From there, you can monitor various aspects of your application's performance, including scheduled jobs.

To monitor a specific scheduled job, you can add custom Telescope entries within the job's code. For example, you can use the Telescope::recordJob method to record information about the job's execution. Here's an example:

use Laravel\Telescope\Telescope;

class MyScheduledJob implements ShouldQueue
{
    public function handle()
    {
        Telescope::recordJob($this->job, 'My Scheduled Job');
        
        // Your job logic here
    }
}

This will record information about the job's execution, such as the number of queries, runtime, and more. You can then view this information in the Telescope dashboard.

Telescope provides a powerful and user-friendly interface for monitoring the performance of your Laravel application, including scheduled jobs. It can be a great alternative to Laravel Debugbar for this specific use case.

Snapey's avatar

I would recommend Spatie Laravel-ray

1 like

Please or to participate in this conversation.