Home » Php » php – i could not run artisan schedule:run cron command at shared hosting

php – i could not run artisan schedule:run cron command at shared hosting

Posted by: admin February 25, 2020 Leave a comment

Questions:

I want to achieve task scheduling in my laravel 5.8 project. For that, I have created a custom artisan command artisan send: credentials which send emails to specific users based on their status.

sendUserCredentials.php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Mail\credentialsEmail;
use App\Models\userModel;
use Mail;

class sendUserCredentials extends Command
{

    protected $signature = 'send:credentials';


    protected $description = 'Credentials send Successfully!';


    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
       $users = userModel::select(["email","username","role","id"])->where("credentials","NO")->get();
       foreach ($users as $key => $user) {
           Mail::to($user->email)->send(new credentialsEmail($user));
           userModel::where("id",$user->id)->update(["credentials"=>"SEND"]);
       }

    }
}

I added this command in kernel.php so that I can run this command using the laravel task scheduler.

kernel.php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{

    protected $commands = [
        Commands\sendUserCredentials::class,
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->command('send:credentials')
                 ->everyMinute();
    }

    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

so on my local server, everything works like a charm when I run this command php artisan schedule:run
but on the shared server when I run scheduler using the cron command *****/path/to/project/artisan schedule:run >> /dev/null 2>&1 it gives me an error like this

local.ERROR: The Process class relies on proc_open, which is not available on your PHP installation. {"exception":"[object] (Symfony\Component\Process\Exception\LogicException(code: 0): The Process class relies on proc_open, which is not available on your PHP installation. at /path/to/vendor/vendor/symfony/process/Process.php:143)

BUT when I run the artisan command directly *****/path/to/project/artisan send:credentials >> /dev/null 2>&1 using the cron job then there is no error and emails send successfully!

How to&Answers:

The Error

The Process class relies on proc_open, which is not available on your PHP installation.

is because of Flare error reporting service enabled in debug mode. To solve this please follow the steps shared below.

Add the File /config/flare.php and add the below content

'reporting' => [
    'anonymize_ips' => true,
    'collect_git_information' => false,
    'report_queries' => true,
    'maximum_number_of_collected_queries' => 200,
    'report_query_bindings' => true,
    'report_view_data' => true,
],

And Clear the Bootstrap cache with below command

php artisan cache:clear && php artisan config:clear

Most probably the issue will be solved. Otherwise check once this link