0
過去3天我一直在爲我的網站設置cron。在我的cPanel我已經提到,這將運行每5分鐘和命令cron是無法爲Laravel4設置Cron
wget http://www.example.com/artisan cron:run
在我的工匠我已經加入
Artisan::add(new CronRunCommand);
而且CronRunCommand.php是
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class CronRunCommand extends Command {
protected $name = 'cron:run';
protected $description = 'Run the scheduler';
protected $timestamp;
protected $messages = array();
protected $runAt = '03:00';
public function __construct()
{
parent::__construct();
$this->timestamp = time();
}
public function fire()
{
$this->everyFiveMinutes(function()
{
// In the function, you can use anything that you can use everywhere else in Laravel.
$affectedRows = User::where('logged_in', true)->update(array('logged_in' => false)); // Not really useful, but possible
Artisan::call('auth:clear-reminders');
$this->messages[] = $affectedRows . ' users logged out';
});
$this->dailyAt('09:00', function()
{
Mail::send('hello', array(), function($message)
{
$message->to('[email protected]', 'Cron Job')->subject('I am still running!');
});
});
$this->finish();
}
protected function finish()
{
// Write execution time and messages to the log
$executionTime = round(((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']) * 1000), 3);
Log::info('Cron: execution time: ' . $executionTime . ' | ' . implode(', ', $this->messages));
}
protected function yearly(callable $callback)
{
if(date('m', $this->timestamp) === '01' && date('d', $this->timestamp) === '01' && date('H:i', $this->timestamp) === $this->runAt) call_user_func($callback);
}
}
而且在我的電子郵件中,我收到此消息: 404 Not Found 2015-09-06 04:38:02錯誤404:未找到。
- 2015-09-06 04:38:02-- ftp://cron/run =>「運行」 解決cron ...失敗:名稱或服務未知。 wget的:無法解析主機地址「的cron」