el *_*uta 2 scheduled-tasks laravel laravel-5 laravel-scheduler
I am using Laravel schedule to run cron jobs.
In my crontab I have added (with correct path to my project):
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)
Now my App\Console\Kernel.php looks like:
protected function schedule(Schedule $schedule)
{
$schedule->command('investments:calculate_interests')->everyMinute();
$schedule->call('\App\Http\Controllers\UsersController@testEvent')->everyMinute();
}
Run Code Online (Sandbox Code Playgroud)
Using it like that I successfully run jobs every minute. But how I can change it to run them on every 10 or 20 or 30 seconds?
我用这段代码解决了它:
public function handle()
{
$count = 0;
while ($count < 59) {
$startTime = Carbon::now();
$this->travelsRequestsDriversRepository->beFreeRequestAfterTime();
$endTime = Carbon::now();
$totalDuration = $endTime->diffInSeconds($startTime);
if($totalDuration > 0) {
$count += $totalDuration;
}
else {
$count++;
}
sleep(1);
}
}
Run Code Online (Sandbox Code Playgroud)
并在 cron 表中添加此命令。
* * * * * /usr/local/php56/bin/php56 /home/hamshahr/domains/hamshahrapp.com/project/artisan taxis:beFreeTaxis 1>> /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14496 次 |
| 最近记录: |