Home > Backend Development > PHP Tutorial > php实现自动运行文件

php实现自动运行文件

WBOY
Release: 2016-06-23 13:34:18
Original
1327 people have browsed it

autoexec.php
Copy after login
<?phpignore_user_abort (); //即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.set_time_limit(30); //执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去$interval=3; //每隔5分钟运行 这个时间间隔可以更改do{    $url = "http://localhost/testUpdate.php";    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_TIMEOUT, 2);    $result = curl_exec($ch);    curl_close($ch);    sleep($interval);// 等待5分钟}while(true);
Copy after login
testUpdate.php
Copy after login
<?php $fp = fopen("test.html","a+");    fwrite($fp,time()."一次\n");    fclose($fp);?>
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template