asp与php中定时生成页面的思路与代码

2023-12-07 0 508

PHP版本的的定时生成页面的:

<?php
$file = dirname(__FILE__).\’/index.html\’;
$timex=time()-filemtime($file); //间隔时间,单位秒
if($timex>7200){ //间隔大于2小时,重新生成
echo \”<script language=javascript src=\’crhtml.php\’></script>\”;
}
?>

ASP版本的的定时生成页面的:

<%
\’不缓存
Response.Buffer = True
Response.ExpiresAbsolute = Now() – 1
Response.Expires = 0
Response.cachecontrol = \”no-cache\”
\’读取最后修改时间
FPath=server.mappath(\”index.html\”)
set fso=server.CreateObject(\”scripting.filesystemobject\”)
If fso.fileExists(FPath) Then
Set f = fso.GetFile(FPath)
crdate=f.DateLastModified
end if
if DateDiff(\”h\”,crdate,now())>10 then \’时间间隔大于一定值
response.write \”<iframe border=0 frameborder=0 scrolling=no width=0 height=0 src=\”\”/crhtml.asp\”\”></iframe>\”
end if
%>

使用方法:在网站的流量大的页面,一般为首页用 iframe 调用上面的代码即可,如插入 <iframe border=0 frameborder=0 scrolling=no width=0 height=0 src=\”/create.asp\”></iframe>
2011-7-9 @ PS更新:正如下面留评论的朋友所说,此种方法的确会增加服务器负担。为了避免这种方式的缺点,有2种方法来解决,

一、减少频繁访问被调用页面的次数,如在流量不大的页面调用 create.asp ;

二、直接使用 linux cron定时服务、或windows计划任务或一些定时执行命令的小软件 例如:hou任务计划。

参考文章如下:

1、linux使用crontab命令定时重启服务器

2、Cron定时执行带参数的PHP代码

3、Cpanel下Cron Jobs定时执行PHP的方法

这样就可以避免频繁调用生成判断页面了,只在需要执行的时候访问一次生成页面即可。

使用了cdn的网站需要注意的问题

鉴于现在很多网站都使用了cdn,如果不断自动生成首页可能导致首页为空的情况下被cdn抓取到导致首页是空内容,那么这样怎么解决呢。

悠久资源网的方案:例如可以生成index_def.htm,然后通过程序判断内容是否有更新,内容是否不为空(内容一般大于30k),这样执行复制操作将index_def.htm复制一份为index.htm即可。

winddow服务器下可以使用vbscript因为比较强大,linux可以使用shell。

vbscript

Dim fso
Set fso = CreateObject(\”Scripting.FileSystemObject\”)
f1=\”F:\\webroot\\jb51net\\index_def.htm\”
f2=\”F:\\webroot\\jb51net\\index.htm\”
fsize=50000 \’50k
set fn2=fso.GetFile(f1)
flsize2=fn2.size
fldate2=fn2.datelastmodified
set fn=fso.GetFile(f2)
flsize1=fn.size
fldate1=fn.datelastmodified
If fso.FileExists(f1) and flsize2>fsize and fldate2>fldate1 Then
fso.getfile(f1).copy(f2)
if err.number=0 then WriteHistory \”成功\”&now()&\”………\”,\”log.txt\”
end if

Sub WriteHistory(hisChars, path)
Const ForReading = 1, ForAppending = 8
Dim fso, f
Set fso = CreateObject(\”Scripting.FileSystemObject\”)
Set f = fso.OpenTextFile(path, ForAppending, True)
f.WriteLine hisChars
f.Close
End Sub

悠久资源网原创文章,免费提供给大家了。

到此这篇关于asp与php中定时生成页面的思路与代码的文章就介绍到这了,更多相关asp定时生成页面内容请搜索悠久资源网以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源网!

您可能感兴趣的文章:

  • linux Cron定时执行带参数的PHP代码
  • Linux服务器配置PHP文件下载,中文乱码问题,下载出错如何解决
  • 用php如何解决大文件分片上传问题
  • 服务器大量php-cgi.exe进程导致CPU占用100%的解决方法
  • Linux系统下安装PHP7.3版本
  • PHP局部异常因子算法-Local Outlier Factor(LOF)算法的具体实现解析

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悠久资源 ASP编程 asp与php中定时生成页面的思路与代码 https://www.u-9.cn/biancheng/asp/127153.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务