ignore_user_abort(); //Close the browser and the PHP script can continue to execute.
set_time_limit(0); //The program can be executed without limit through set_time_limit(0)
The code is as follows:
<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> ?>
The above introduces the PHP scheduled tasks and PHP scheduled tasks, including the content of PHP scheduled tasks. I hope it will be helpful to friends who are interested in PHP tutorials.