在php中运行重复任务


Running repeated tasks in php

我使用以下代码从网站获取一些信息并将其保存在本地。

$ch = curl_init("http://test.com/test.txt");
$fp = fopen("test.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

现在,test.txt需要定期更新。如何在特定时间间隔触发此操作?

如果你使用*nix或Mac(甚至Cygwin),你可能最好使用wget:

@hourly wget http://test.com/test.txt

这将完成cURL调用将要执行的所有操作,并且每小时执行一次。这里有一个很好的cron介绍:https://help.ubuntu.com/community/CronHowto