php不能run as,PHP artisan + 命令能执行 PHP artisan schedule:run 却不能执行?

开发环境 Mac + homestead

过程:我在命令行下用 php artisan make:console创建了一个artisan command。代码如下

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Models\Order;

class Automaric extends Command

{

/**

* The name and signature of the console command.

*

* @var string

*/

protected $signature = 'test';

/**

* The console command description.

*

* @var string

*/

protected $description = '尝试计划任务';

/**

* Create a new command instance.

*

* @return void

*/

public function __construct()

{

parent::__construct();

}

/**

* Execute the console command.

*

* @return mixed

*/

public function handle()

{

$orders = Order::where('id', '>', 6000)->get();

foreach ($orders as $order) {

$order->feedbackrecord = 5;

$order->remark = 'test';

$order->save();

}

$this->info('test');

return true;

}

}

然后我的kernel代码如下

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 = [

Commands\Inspire::class,

Commands\Automaric::class,

];

/**

* Define the application's command schedule.

*

* @param \Illuminate\Console\Scheduling\Schedule $schedule

* @return void

*/

protected function schedule(Schedule $schedule)

{

$schedule->command('Automaric')->everyMinute();

}

}

我在命令行下直接运行 php artisan test 得到了 Automaric类里handle()方法的预期结果。

我在 homestead 环境里编写了 crontab -e 加入了 * * * * * php /home/vagrant/Code/sample/artisan schedule:run >> /dev/null 2>&1 这行代码。得到 crontab: installing new crontab的结果。但是却没有得到 php artisan test的结果。我接着在命令行下运行 php artisan schedule:run 得到 Running scheduled command: '/usr/bin/php7.0' 'artisan' Automaric > '/dev/null' 2>&1 & 但是数据库还是没有改变。

我尝试把 crontab -e 的 php 改成绝对路径 /usr/bin/php 但结果也不行。我搜索了谷歌与百度。论坛也搜索了 cron 和”任务调度“关键字相关的帖子。但还是未找到解决办法。

请论坛有时间有能力的朋友告诉我一下原因,或者给我一个思路。???。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值