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

mstdmstd's avatar

scheduled tasks In laravel 5.7 app triggered at wrong time

Hallo, In laravel 5.7 app I have a problem that scheduled tasks with email sending are recieved at wrong time. in my ubuntu 16 under Digital Ocean Server in crontab with command :

crontab -e

I added line :

* * * * * cd /var/www/html/the-box-booking && php artisan schedule:run >> /dev/null 2>&1

php in browser shows next :

PHP Version 7.1.17-1+ubuntu16.04.1+deb.sury.org+1
...
date
date/time support   enabled
timelib version 2016.05
"Olson" Timezone Database Version   0.system
Timezone Database   internal
Default timezone    Asia/Dubai
Directive   Local Value Master Value

date.default_latitude        31.7667     31.7667
date.default_longitude       35.2333     35.2333
date.sunrise_zenith          90.583333   90.583333
date.sunset_zenith           90.583333   90.583333
date.timezone                Asia/Dubai  Asia/Dubai

I suppose that console command use cli configurations. I check in command line :

 php -v
PHP 7.1.17-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: May  5 2018 04:55:21) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.17-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

I open /etc/php/7.1/cli/php.ini and see:

[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Asia/Dubai Timezone = Asia/Dubai

I set "timezone" of app/config.php :

    'timezone' => 'Asia/Dubai',

In bootstrap/app.php I added line :

date_default_timezone_set('Asia/Dubai');

In app/Console/Kernel.php I added line :

    protected function schedule(Schedule $schedule)
    {
        \Log::info( 'report:available-spaces-by-zones Report run # ' . time()  );
        $schedule->command('report:available-spaces-by-zones')->daily('18:00');
    }

as a result I see a lot of info lines in my logs, but time of report sent if different. Today I recieved it at 21 pm.

I restarted cron, apache and OS.

Where error and how to fix it?

Thanks!

0 likes
3 replies
Dalma's avatar
Dalma
Best Answer
Level 6

For my schedules I specify the timezone. Below is an example from the Laravel docs

$schedule->command('foo')
          ->weekdays()
          ->hourly()
          ->timezone('America/Chicago')
          ->between('8:00', '17:00');
1 like
mstdmstd's avatar

i modified my app/Console/Kernel.php file as :

    protected $commands = [
        'App\Console\Commands\reportAvailableSpacesByZones'
    ];

    protected function schedule(Schedule $schedule)
    {
        \Log::info( 'report:available-spaces-by-zones Report run # ' . time()  );
        $schedule
            ->command('report:available-spaces-by-zones')
            ->timezone('Asia/Dubai')
            ->daily('7:00');

    }

As as result I got am email at midnight of 'Asia/Dubai' timezone. Looks like my timezone options are ignored and run always at midnight of 'Asia/Dubai' timezone. Any ideas why so and how to fix it ?

  1. I suppose that my schedule uses settings in /cli/php.ini and can not see these settings in browser's phpinfo output.
  2. Is there is a way to check/view settings in /cli/php.ini of my server ?
kitchh's avatar

I guess you have checked, but still, did you verify the timezone settings on your server? Is it pointing to correct timezone and showing the current dubai time when you check the the time on the server?

Please or to participate in this conversation.