简体   繁体   中英

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

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!

I am using laravel 5.8 and deployed my website on namecheap shared hosting. Following command help me to execute cron job properly:

*/5 *   *   *   *   /usr/local/bin/php /home/YOUR_USER/public_html/artisan schedule:run >> /home/YOUR_USER/public_html/cronjobs.txt

As namecheap allow minimum of 5 min interval, so above command will execute after 5 min and output will be displayed in a text file.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM