一,创建command
1,执行命令
liuhongdi@lhdpc:/data/api$ php artisan make:command IndexAllCommand
2,查看创建的文件:
<?phpnamespace App\Console\Commands;use Illuminate\Console\Command;class IndexAllCommand extends Command
{/*** The name and signature of the console command.** @var string*/protected $signature = 'app:index-all-command';/*** The console command description.** @var string*/protected $description = 'Command description';/*** Execute the console command.*/public function handle(){echo "开始执行命令:";}}
注意: signature是从命令行执行的命令名,而不是文件名,
从命令行执行时,只能使用在此处指定的命令名
二,从命令行运行
root@lhdpc:/data/api# runuser -u www-data php artisan app:index-all-command
开始执行命令:
说明:使用runuser是因为要和php在nginx/php-fpm中的运行用户保持一致,
否则会出现权限问题