Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ApeWare's avatar

Scheduler pingBefore() does not seem to work

We have guzzlehttp/guzzle 6.3.0 installed.

I am trying to move a bunch of legacy CRON jobs from an old server over to the Laravel scheduler. The CRON jobs we are moving simply CURL a url that handles various DB caching processes and such.

I set up some schedules like this and they work fine:

$schedule->call(
    function(){
        $client = new Client(); //GuzzleHttp\Client
        $client->request('GET', 'https://mydomain.com/route/to/php/file.php');
        Log::info("Ran process x");
    }
)
->timezone('America/New_York')
->weekdays()
->at('7:00');

After reviewing the docs further, and because I have about 20+ of these tasks to schedule, I wanted to simplify the call and reduce the code lines. I came up with this:


$schedule->call(function(){Log::info('Ran process x');})
    ->pingBefore('https://mydomain.com/route/to/php/file.php')
    ->timezone('America/New_York')
    ->weekdays()
    ->at('7:00');

I set up the pingBefore() route to write something to the DB just so I could verify that the pingBefore() actually fires; the pingBefore() does not seem to be working. The log is written but not the DB. I can hit the route manually and the DB is written to so it is not an issue with the route. I am testing this locally by running php artisan schedule:run. For the purpose of testing I scheduled the test task to run every minute.

Does anyone have any experience with the pingBefore()method or see any reason this wouldn't work? I want to hit a route and log that the task was run.

0 likes
1 reply
afrayedknot's avatar
Level 14

In 5.4 the callback event does not call the before hooks. This has been fixed in 5.5

You can either upgrade to 5.5, or continue to use 5.4, but switch to putting the tasks into "commands" - which correctly uses the before hooks.

The other option is to switch to pingAfter() - that'll work as is.

1 like

Please or to participate in this conversation.