這是我的控制器看起來像
cron作業
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Cron extends Controller {
public function before() {
if(!Kohana::$is_cli) ;
}
public function action_index() {
$myFile = "C:\cron.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "\n");
$stringData = date('Y-m-d H:i:s');
fwrite($fh, $stringData);
fclose($fh);
}
}
?>
我運行通過命令行使用腳本這個
php "C:\Program Files (x86)\EasyPHP\www\myweb\index.php" --uri=cron/index
其中的cron是控制器和指數是一個函數。
現在我需要的是當我通過瀏覽器運行腳本來運行該腳本每x分鐘
,這僅僅是時間的C:\ cron.txt是改性。 我心臟通過把這個
public function before() {
if(!Kohana::$is_cli) ;
}
是避免通過瀏覽器的任何訪問? 因此, 1.我該如何拒絕來自瀏覽器的訪問? 2.如何讓代碼每x分鐘運行一次?
HTTP_Exception_403給我一個ExceptionError,通常它顯示403錯誤頁面 – DeathCoder
你必須改變你的index.php捕捉這些例外並做相應的動作,如顯示一個空白頁面或簡單的403頁面,如'
403 Forbidden
'。如果你正在使用Kohana 3.3,你應該使用minion作爲CLI的東西。我更新了捕獲異常的'index.php'部分的代碼 – pocesar