求一段php代码

来源:百度知道 编辑:UC知道 时间:2024/06/23 09:17:45
php定期把一个网页保存下来.
比如我要每隔一个小时把 www.163.com/index.html
保存下来?该怎么保存呀?
代码是?

<?php
//一般这种操作是有一个访问来触发的。
//试想没人访问,要更新又有什么用呢?
$inputname = "";//输入的url或文件路径
$outputname = "";//输出的文件
$modify_time == false;
if(file_exists($outputname)){
$modify_time = filectime($outputname);//获取修改时间
}
$interval = time()-$modify_time; //获取的修改时间间隔
if($interval > 1*60*60){//1小时间隔
createFile($inputname,$outputname)
}

function createFile($inputname,$outputname){
$error = true;
$handle = @fopen($inputname,"r");
if($handle){
while(!feof($handle)){
$line = fgets($handle);
$data .= $line;
}
fclose($handle);
}else{
$error = "文件不存在:$inputname";
}
if($data){
$handle = fopen($outputname,"w+");
$result = fwrite($handle, $data);
//echo '<div class="create">更新文件:'.$outputname.' <span>成功</span>