我想每5分鐘運行我的php腳本。這是我的PHP代碼。沒有cron的PHP調度器
function call_remote_file($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
}
set_time_limit(0);
$root='http://mywebsiteurl'; //remote location of the invoking and the working script
$url=$root."invoker.php";
$workurl=$root."script.php";
call_remote_file($workurl);//call working script
sleep(60*5);// wait for 300 seconds.
call_remote_file($url); //call again this script
我運行這段代碼一次。即使在關閉整個瀏覽器窗口之後,它仍能正常工作。
問題是停止工作,如果我打開我的系統的互聯網連接。
如何解決這個問題。請幫助我。
你想每5分鐘執行一次腳本嗎?爲什麼不是一個cron工作? – Josh 2012-02-11 07:37:47
爲什麼不cron?我不明白你爲什麼驚訝,如果你的計算機沒有連接到網絡,它會停止從你的計算機調用腳本。 – 2012-02-11 07:38:02
我的猜測是他/她無法訪問主機上的cron。 – 2012-02-11 07:39:55