这个问题还是有点研究价值~~一般用ajax后,交互性强了很多,用起来比较爽但是LZ提出的问题,也确实存在除非用自己的server 请唠叨来解决 哈哈~~

解决方案 »

  1.   

    http请求是无状态的,一次发送接收算一次,没办法一直连着
      

  2.   

    我在网上找到一篇这个,不知能不能联系上啊:php实现后台线程持续运行 
    2005年12月21日00:24星期三  [技术相关] 
    见codestartthread.php<?PHP
    include_once("System/SharedMemory.php");
    $shared_memory =& System_SharedMemory::factory();
    set_time_limit(0);
    ignore_user_abort(true);
    $pid=(int)$shared_memory->get("thread_pid");
    if($pid>0)

     die("线程已经在活动中");
    }
    $pid=posix_getpid();
    $shared_memory->set("thread_pid",$pid);
    while(1)

     $fp=fopen(ROOT_PATH."temp/running.txt","a+");
     fwrite($fp,date("Y-m-d H:i:s")."\n");
     fclose($fp);
     sleep(5);
    }
    ?>stopthread.php
    <?php
    include_once("System/SharedMemory.php");
    $shared_memory =& System_SharedMemory::factory();
    $pid=(int)$shared_memory->get("thread_pid");
    if($pid==0)

     die("线程并没有在活动");
    }
    if(posix_kill($pid,9))

     $shared_memory->set("thread_pid",0);
     echo "线程终止";
    }
    else

     echo "线程无法终止";
    }
    ?>在浏览器中访问startthread.php之后,把浏览器关掉。要终止访问stopthread.php。SharedMemory是pear的一个project,具体情况大家可以google。这里互斥使用了一个变量thread_pid,其实也可以使用一个文件,打开,flock住。