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:
-
Administrator is submitting the admin generator form data.
-
Data is getting inserted in the database.
-
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.