首页 > 后端开发 > php教程 > php计划任务 php定时任务

php计划任务 php定时任务

WBOY
发布: 2016-07-28 08:25:55
原创
892 人浏览过

ignore_user_abort(); //关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(0); // 通过set_time_limit(0)可以让程序无限制的执行下去

代码如下:

<span> 1</span> <span>php
</span><span> 2</span><span>ignore_user_abort</span>(); 
<span> 3</span><span>set_time_limit</span>(0); 
<span> 4</span><span>$interval</span> = 5; <span>//</span><span> 每隔5秒运行</span><span> 5</span><span>$k</span> = 0<span>;
</span><span> 6</span><span>do</span><span> {
</span><span> 7</span><span>$time</span> = <span>time</span><span>();
</span><span> 8</span><span>$file</span> = './test.txt'<span>;
</span><span> 9</span><span>$content</span> = "cron:".<span>date</span>('Y-m-d H:i:s')<span>;
</span><span>10</span><span>$fp</span> = <span>fopen</span>(<span>$file</span>, 'a'<span>);
</span><span>11</span><span>fwrite</span>(<span>$fp</span>, <span>$content</span><span>);
</span><span>12</span><span>fclose</span>(<span>$fp</span><span>);
</span><span>13</span><span>if</span>(<span>$k</span>>=5<span>){ 
</span><span>14</span><span>break</span><span>;</span><span>15</span><span>       }
</span><span>16</span><span>$k</span>++<span>;</span><span>18</span><span>sleep</span>(<span>$interval</span>); <span>//</span><span> 等待5秒钟</span><span>19</span>    } <span>while</span> (<span>true</span><span>);
</span><span>20</span><span>21</span> ?>
登录后复制

以上就介绍了php计划任务 php定时任务,包括了php计划任务方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板