- ·上一篇文章:linux(nginx)服务器时间同步问题的解决方法
- ·下一篇文章:linux中如何将几个文件夹和文件一起压缩到一个zip文件中?
nginx服务器定时运行thinkphp开发的功能
功能:在nginx服务器上定时运行thinkphp开发的一个功能
来源:www.K88.NET
注意:
首先:我们在thinkphp的控制器中添加一个函数log()
函数功能:先获取服务器当前时间,然后将时间追加到newfile.txt中,代码如下:
public function log()
{
 
 
$path = dirname(dirname(dirname(dirname(__FILE__))))."/log1/newfile.txt"
 
 
$myfile = fopen($path, "a+") or die("Unable to open file!")
 
 
$txt = date("Y-m-d H:i:s")."\n"
 
 
fwrite($myfile,$txt)
 
 
fclose($myfile)
}
[root@aaa]
# crontab -e
回车,打开编辑框,在里面输入
*/1 * * * * wget http://localhost/index/log.html 
--每隔1分钟运行一次
10 13 * * * 
wget http://localhost/index/log.html 
--每天13:10分运行一次
wget http://localhost/index/log.html 
--每天13:10分运行一次
然后输入:wq保存
这样就完成了nginx定时运行thinkphp开发的功能了。当时间到达后,你去当前目录下log1文件夹下看看有没有newfile.txt文件。如果有这个文件,说明已经定时运行了thinkphp功能了。
不过要注意一点:像第一种,每隔1分种运行一次,不太受到影响;但第二种,定在13:10分运行这种,可能因为nginx服务器时间和个人电脑上的时间不一致,看不到newfile.txt文件。
nginx服务器定时运行thinkphp开发的功能