>  기사  >  백엔드 개발  >  php实现自动运行文件

php实现自动运行文件

WBOY
WBOY원래의
2016-06-23 13:34:181285검색

autoexec.php
<?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);
testUpdate.php
<?php $fp = fopen("test.html","a+");    fwrite($fp,time()."一次\n");    fclose($fp);?>


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.