I have a statusUpdate.php file in the xampp\htdocs\project\app\Console\Commands folder.
statusUpdate.php :
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class statusUpdate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'status:update';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update Job status daily';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$affected = DB::table('jobs')->update(array('status' => 1));
}
}
I created it following the official Laravel documentation. After that, I added \App\Console\Commands\statusUpdate::class to the Kernel.php file located in xampp\htdocs\project\app\Console.
Here's the code from the Kernel.php file:
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\App\Console\Commands\statusUpdate::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('status:update')
->everyFiveMinutes();
}
}
I then ran the following command using CMD on Windows:
php artisan schedule:run
Now, it works fine on my local server. The status field in my jobs table updates correctly to 1.
However, when I deployed this project to shared hosting and set up a CRON job in cPanel, it didn't work. The CRON job command is:
php /path/to/artisan schedule:run 1>> /dev/null 2>&1
In this hosted environment, the command isn't functioning. How can I solve this issue?
php
interpreter as well in your cron job command:/path/to/php /path/to/artisan schedule:run 1>> /dev/null 2>&1
. You can get the absolute path to yourphp
binary from the PHP_BINDIR reserved constant. – Aversion