在php中运行重复的任务

时间:2014-11-04 04:04:32

标签: 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。如何在特定的时间间隔触发?

1 个答案:

答案 0 :(得分:1)

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

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

这将完成cURL调用所做的所有事情,并按小时执行。这是一个很好的cron简介:https://help.ubuntu.com/community/CronHowto

相关问题