Strange behavior with cron and laravel scheduler

Hello, I have configured a cron job with plesk in my droplet to run a laravel command every minute /opt/plesk/php/7.1/bin/php /var/www/vhosts/website/laravel/artisan schedule:run This executes the Laravel scheduler, that is filled with tasks to run at certain time, lets say send emails at 10:00 and send SMS at 11:00

So when the cron runs the scheduler and a task is found at the same time it executes the task, eg 9.58 no tasks 9.59 no tasks 10:00 send emails 10:01 no tasks

My problem is that FOR SOME STRANGE REASON the scheduler is delayed at some times, so the problem is like this 9.58 no tasks 9.59 no tasks 10:01 no tasks 10:01 no tasks

If I run this command from command line, it runs instantly, with no delay. But for some reason when this is executed from the cron, sometimes is delayed. I have tested the cron from inside plesk, there is a button Run now and is true, for some reason sometimes it takes about 65 seconds to run the cron job or the command artisan schedule:run

Any ideas? This only happens in the droplet I have, not in local environment.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

The issue was caused by depleted entropy by PHP script.

To resolve the issue generate entropy by using haveged daemon:

  1. Enable EPEL repository:

    yum install epel-release

  2. Install daemon with the following command and enable it:

    chkconfig haveged on
    systemctl start haveged```

Interesting indeed. The strace tool would have definitely helped in pinpointing the lag. So if “php” is different from “/opt/plesk/php/7.1/bin/php”, I wonder what’s in plesk’s php that would cause such a lag. I was suspecting something was off with php hence my asking to at switch to 5.6 or 7.2 as that would imply skipping modules, ini settings, and other oddities that could be under 7.1.

I wonder what php version is the cli one:

which php php -v

Hopefully whatever the Plesk engineer did is a good long term fix.


@unixynet I have fresh news:

Yesterday I have created a simple php script and named it test2.php

echo date(‘Y-m-d H:i:s’) . PHP_EOL;

As I’m using laravel and it needs PHP 7.1, my cron call php files with php 7.1 path: /opt/plesk/php/7.1/bin/php test2.php and not using the default 5.6 php cli: php test2.php

The interesting thing is that if I run from console it hits a moment that the system is lagged and stops execution, then resume it after some minutes… watch -n1 /opt/plesk/php/7.1/bin/php /var/www/vhosts/

But if I run with only php, never is stopped, even when the system is lagged… watch -n1 php /var/www/vhosts/

I have waited to a lag window (lasts about 3-5 minutes) and when using php 7.1 the system is stopped (I cant run any php script using the 7.1 path) BUT the system let me to run using only php….

Example watch -n1 php /var/www/vhosts/ runs forever as it should…

Today an engineer from Plesk have accessed the server and he told me he can’t reproduce the “watch” test, mysteriously after he has logged in to the server, the issue disappeared and now the server is running smooth as it should (for now).

I’ll update if the issue is still going on.

Thank you for your time.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel