首頁  >  文章  >  後端開發  >  php規劃任務 php定時任務

php規劃任務 php定時任務

WBOY
WBOY原創
2016-07-28 08:25:55861瀏覽

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教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn