我试图运行,抓住比特币的价格每分钟调度,并将其添加到数据库中,但我不能让幼虫调度才能正常运行。
我测试过的SQL代码在一个单独的PHP页面和它的作品,但调度似乎并没有运行
日程安排功能是kernel.php手柄的功能是在乔布斯/ UpdateRates
protected function schedule(Schedule $schedule)
{
$schedule->job(new \App\Jobs\UpdateRates)->everyMinute();
}
public function handle()
{
$url = "https://bitpay.com/api/rates";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
$rate = $data[1]["rate"];
$usd_price = 10; # Let cost of elephant be 10$
$bitcoin_price = round( $usd_price / $rate , 8 );
DB::insert('insert into settings (bitcoin_rate, monero_rate) values (?, ?)', [0, 1]);
}
您需要添加到的cron:
VIM / etc / crontab中
修复路径到你的项目,加入这一行
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
这是什么叫Laravel,然后你可以从Laravel项目范围内做你的计划的其余部分。
现在,你可以添加这样的任务,而不必再担心更新的cron。
protected function schedule(Schedule $schedule)
{
$schedule->job(new DailyEmailReports)->dailyAt();
$schedule->job(new SomeOtherThing)->hourly();
$schedule->job(new SomeElse)->everyFiveMinutes();
}