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

MehulBawadia's avatar

Laravel 5.3 Queues not working in shared hosting

In my Laravel 5.3.* application, I am having queues running in the background. This works completely fine in my local machine. But when this is made live on the server (shared hosting), it doesn't work at all.

Here's the scenario:

  1. Administrator is submitting the admin generator form data.

  2. Data is getting inserted in the database.

  3. Shoot an email regarding the same.

So, in order to have this functionality going smoothly, I have created a cron job on my server's cPanel.

/usr/local/bin/php /home/<username>/laravel-app/artisan schedule:run >/dev/null 2>&1

And here's the app/Console/Kernel.php file content

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    // $schedule->command('inspire')
    //          ->hourly();

    $schedule->command('queue:work --daemon --tries=3')
             ->everyMinute()
             ->withoutOverlapping();
}

And I have also created the database for jobs by running

php artisan queue:table;
php artisan queue:failed-table;
php artisan migrate;

When the administrator is generated/inserted, an event is fired:

event(new AdministratorHasBeenGenerated($user, $request->password));

which will send a welcome email to the provided email id (in app/Listeners/AdministratorHasBeenGenerated/SendWelcomeEmail.php)

/**
 * Handle the event.
 *
 * @param  AdministratorHasBeenGenerated  $event
 * @return void
 */
public function handle(AdministratorHasBeenGenerated $event)
{
    Mail::to($event->administrator->email)
          ->queue(new GeneratedMail($event->administrator, $event->password));
}

And here's the mail configs in the .env file

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=correct_username
MAIL_PASSWORD=correct_password
MAIL_ENCRYPTION=null

UPDATE 1:

Depending upon the shared hosting server requirements to send emails , I have changed the MAIL_* settings in .env file:

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Here's the log file with the error message:

[2016-12-29 08:08:02] local.ERROR: exception 'ErrorException' with message 'proc_open(): fork failed - Resource temporarily unavailable' in /home/<username>/laravel-app/vendor/symfony/console/Application.php:941
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'proc_open(): fo...', '/home/benfit/la...', 941, Array)
#1 /home/benfit/laravel-app/vendor/symfony/console/Application.php(941): proc_open('stty -a | grep ...', Array, NULL, NULL, NULL, Array)
#2 /home/benfit/laravel-app/vendor/symfony/console/Application.php(729): Symfony\Component\Console\Application->getSttyColumns()
#3 /home/benfit/laravel-app/vendor/symfony/console/Style/SymfonyStyle.php(354): Symfony\Component\Console\Application->getTerminalDimensions()
#4 /home/benfit/laravel-app/vendor/symfony/console/Style/SymfonyStyle.php(52): Symfony\Component\Console\Style\SymfonyStyle->getTerminalWidth()
#5 /home/benfit/laravel-app/vendor/laravel/framework/src/Illuminate/Console/OutputStyle.php(29): Symfony\Component\Console\Style\SymfonyStyle->__construct(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /home/benfit/laravel-app/vendor/laravel/framework/src/Illuminate/Console/Command.php(153): Illuminate\Console\OutputStyle->__construct(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /home/benfit/laravel-app/vendor/symfony/console/Application.php(821): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /home/benfit/laravel-app/vendor/symfony/console/Application.php(187): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Console\Scheduling\ScheduleRunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /home/benfit/laravel-app/vendor/symfony/console/Application.php(118): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /home/benfit/laravel-app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /home/benfit/laravel-app/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 {main}

I don't receive any errors or things as such, but neither I receive any welcome email even though I provide correct email id.

Can anybody point out the mistake as to where and what I must have done? It has been more than 4 hours and I couldn't find any solution to this.

Any help is highly appreciated. Thanks.

0 likes
6 replies
Snapey's avatar

that withoutOverlapping is probably the culprit.

it's a definite weakspot in the framework

it uses a lock file in the storage folder and if your scheduled job falls over sometimes the lock file is left behind and your job never runs.

check for that...

1 like
MehulBawadia's avatar

Got this exception in failed_jobs table..

Connection could not be established with host mailtrap.io

What should I do next?

Snapey's avatar

check your .env file on production for mailtrap key etc

MehulBawadia's avatar

It is the same as what I have provided in the question above.

Snapey's avatar

do you have events queued or is the queue being serviced?

Did you see my post about withOverlapping? how have you ruled that out?

Why not insert some logging so you can see what us happening?

MehulBawadia's avatar

@Snapey I have updated the question, kindly have a look at it. I have provided the stack trace of from laravel.log file.

Now, the error/bug is that, the jobs are sending mail as per requirement, but, I still don't receive any mails in my inbox/junkbox..

Please or to participate in this conversation.