Maison > Article > développement back-end > php计划任务 php定时任务
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教程有兴趣的朋友有所帮助。