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

Hashcrypthash's avatar

Connection Refused Error When Running Laravel Cron Jobs

Hi everyone,

I’m running into a “connection refused” error in my Laravel application when executing cron jobs. Here’s what I’ve checked and tried so far:

Verified that the database credentials in .env are correct.

Increased the database connection limit from 15,000 to 25,000 on the DB server.

The error still persists during cron execution, but the app works fine when accessed via the browser.

Has anyone experienced this issue with Laravel cron jobs before? Could it be related to how the cron environment loads .env or something else I might be missing?

Here’s a snippet of my cron command for reference:

          • cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1

Any suggestions or troubleshooting steps would be really appreciated!

Thanks in advance.

0 likes
5 replies
Snapey's avatar

your cron task should be owned by the same user as the web server

Did you specify -u username when creating, or is it running under your user account?

Hashcrypthash's avatar

Yes, user is same. I've added below command in my application's domain cpanel under cron jobs menu

cd /path-to-project && php artisan schedule:run >> /dev/null 2>&1

In console/kernal.php I've defined different jobs which will run by above command

The error I'm getting is not specific to the jobs but since our application's major part is crons that's why it's getting more affected. When this error occurs laravel application also stops for some seconds and showing site couldn't be reached message.

Snapey's avatar

@Hashcrypthash maybe one if your kernel tasks is taking a long time or consuming all the resources.

I usually write all my sheduled tasks as commands so that they can be run manually at any time, and then schedule them to run at different intervals.

Hashcrypthash's avatar

Yes, it also could be the reason the due to more memory occupied the crons stopped randomly? Because on connection refusel it throws an error that I can see in logs. But sometimes crons stops randomly without giving any kind of error.

Is there any specific reason on writing commands instead of schedule jobs? Because for now I've added jobs to run at different time.

Snapey's avatar

@Hashcrypthash you can write command and then schedule it. I explained the reason.

https://laravel.com/docs/12.x/scheduling#scheduling-artisan-commands

So for instance, I can run php artisan archive at any time to test, or re-run the command

or schedule. Schedule::command('archive')->daily();

And, yes, if php runs out of memory there will be no log. But, cron should fire again a minute later

Be careful, if your task takes longer than one minute, you could get a second copy at minute 2 and then a third copy at minute 3, with each taking longer and longer until they all fail.

If your scheduled tasks might overlap, you can use withoutOverlapping()

https://laravel.com/docs/12.x/scheduling#preventing-task-overlaps

Please or to participate in this conversation.