发表时间:2010-09-06 文章分类:PHP 阅读:541200


ignore_user_abort(true);           // 即使Client断开(如关掉浏览器),PHP脚本也可以继续执行.
set_time_limit(0);             // 执行时间为无限制,php默认的执行时间是30秒,通过set_time_limit(0)可以让程序无限制的执行下去
$interval = 300;               // 时间间隔 单位 秒
$key_file="key.txt";          // 配置文件

if ( isset($_GET['s']) ) {
  if ( $_GET['s'] == "0" ){        // 停止工作,但不退出
    echo "关闭";
  } elseif ( $_GET['s'] == "1" ) {      // 工作
    echo "开启";
  } elseif ( $_GET['s'] == "2" ) {      // 退出
    echo "退出";
  } else {
    die("Err 0:stop working 1:working 2:exit");
  $string = "<?php\n return \"".$s."\";\n?>";

if ( file_exists( $key_file ) ) {
    $mkey = include $key_file;
    if ( $mkey == "true" ) {          // 如果工作
    /////////////////////  工作区间  //////////////////////////////////
  $filename = "index.php";
  $contents = file_get_contents("" . $filename);
  $f = fopen("index.html","w");
    } elseif ( $mkey=="die" ) {        // 如果退出
    sleep($interval);           // 等待$interval秒
  } while ( true ) ;
} else {
  die( $key_file . " 不存在 !" );

function write_inc( $path , $strings , $type = false )
  $path = dirname(__FILE__) . "/" . $path;
  if ( $type == false ) {
    file_put_contents( $path , $strings , FILE_APPEND );
  } else {
    file_put_contents( $path , $strings );



ignore_user_abort() 函数设置与客户机断开是否会终止脚本的执行。如果设置为 true,则忽略与用户的断开,如果设置为 false,会导致脚本停止运行,如果未设置该参数,会返回当前的设置。



程序就会根据设置的$interval 定时运行了




用户【37.233.27.*****】说:dZDETz I truly appreciate this article post.Really thank you! Really Great.

用户【27.150.243*****】说:This is the precise blog for anybody who desires to find out about this topic. You notice so much its nearly arduous to argue with you (not that I truly would need匟aHa). You definitely put a brand new spin on a topic thats been written about for years. Nice stuff, simply great!

用户【27.150.243*****】说:I must point out my love for your kindness for men and women who must have assistance with in this concern. Your personal dedication to getting the solution all through came to be rather functional and has in most cases helped women like me to attain their dreams. Your entire valuable useful information signifies so much to me and even further to my fellow workers. Thank you; from each one of us.

用户【27.150.243*****】说:I抎 have to test with you here. Which is not something I usually do! I get pleasure from reading a put up that may make folks think. Also, thanks for permitting me to remark!

用户【27.150.243*****】说:I enjoy you because of your entire labor on this web site. Betty really loves engaging in investigation and it is simple to grasp why. We all notice all of the powerful medium you give simple ideas via your website and therefore invigorate contribution from visitors about this subject matter so our girl has always been being taught a great deal. Have fun with the remaining portion of the new year. You are doing a fabulous job.

用户【155.254.96*****】说:Thank you so much with regard to giving me personally an update on this subject matter on your site. Please know that if a brand-new post becomes available or if any alterations occur on the current posting, I would want to consider reading a lot more and understanding how to make good using of those techniques you write about.Thanks for your time and consideration of other men and women by making this site available.

用户【31.184.236*****】说:&lt;a href=&quot;;&gt;canadian pharmacy no prescription&lt;/a&gt; &lt;a href=&quot;;&gt;canadian pharmacy&lt;/a&gt; &lt;a href=&quot;;&gt;mexican pharmacy no prescription needed&lt;/a&gt; &lt;a href=&quot;;&gt;Canadian Online Pharmacy&lt;/a&gt; &lt;a href=&quot;;&gt;viagra and cialis sample pack&lt;/a&gt; &lt;a href=&quot;;&gt;viagra prescription price&lt;/a&gt; &lt;a href=&quot;;&gt;online pharmacies canada&lt;/a&gt; &lt;a href=&quot;;&gt;best india viagra and price&lt;/a&gt; &lt;a href=&quot;;&gt;cialis_original_10mg&lt;/a&gt; &lt;a href=&quot;;&gt;free viagra samples before buying&lt;/a&gt;

用户【27.150.243*****】说:Can I simply say what a reduction to seek out someone who truly knows what theyre speaking about on the internet. You positively know find out how to bring a difficulty to mild and make it important. Extra folks need to read this and understand this side of the story. I cant imagine youre no more common because you definitely have the gift.

用户【93.188.37.*****】说:На нашем портале мы предлагаем огромный выбор роз. Варианты букетов роз вы сможете посмотреть и заказать подходящие для вас розы в нашем каталоге. [url=]букет невесты 2017[/url]. На портале вы можете приобрести недорогие цветы в Харькове с доставкой. Также с помощью нашего ресурса вы имеете послать букет роз по Интернету с помощью курьерской экспресс доставки. Мы продаём классические и дизайнерские букеты роз различных оттенков и видов, букеты для свадеб, а ещё подарки и различные сладости. У нас трудятся абсолютно опытные флористы, которые красиво оформят каждый заказ для доставки роз по Харькову и другим крупным городам области. [url=]букет квітів троянди купити[/url]. У нас очень дешёвые и красивые розы в Харькове! Наши розы с доставкой по Харькову пользуются огромным спросом. Наши квалифицированные и профессиональные курьеры смогут в кратчайшее время доставить приобретённые розы в Харькове или по области независимо от места расположения адресата и времени суток. [url=]троянди букет замовлення[/url]. Приобрести букет роз или несколько букетов с доставкой по городу и области вы можете как по телефонам, указанным на нашем сайте, так и оставив заявку на приобретение с доставкой. Наши сотрудники уточнят все подробности по заказу и отправят его по нужному адресату в очень сжатый срок.


用户【27.150.243*****】说:It抯 arduous to search out educated folks on this subject, but you sound like you understand what you抮e speaking about! Thanks

用户【27.150.243*****】说:I not to mention my pals appeared to be looking at the nice recommendations from your web site and all of the sudden got a horrible suspicion I never expressed respect to the blog owner for those tips. These young men were as a consequence happy to read through them and have now undoubtedly been enjoying them. Many thanks for truly being very accommodating and for considering varieties of decent information most people are really desirous to be aware of. My very own sincere regret for not expressing appreciation to sooner.

用户【27.150.243*****】说:That is the precise blog for anyone who wants to find out about this topic. You understand so much its virtually onerous to argue with you (not that I truly would want匟aHa). You undoubtedly put a new spin on a subject thats been written about for years. Great stuff, simply great!

用户【115.60.56.*****】说:bulk wholesale standard size cotton tote bag bulk wholesale standard size cotton tote bag

用户【115.60.56.*****】说:Oem Production Diy Messenger Canvas Beach Bag For Girls Oem Production Diy Messenger Canvas Beach Bag For Girls