失败是指关闭浏览器后c.txt还在写进去b吗
我试了下代码,关了浏览器后c.txt里的b的数量就不会再增加了

解决方案 »

  1.   

    好久不见了,都在哪里发财?你的测试程序的写法好象有问题
    一般基本的测试程序应写成这样
    <?php
    function foo() {
      $s = 'connection_status '. connection_status();
      file_put_contents('__.txt', $s);

    register_shutdown_function('foo');
    set_time_limit(10);
    for($i=0; $i<100000000; $i++)
      echo $i;
    ?>__.txt文件的内容将是
    1、程序正常结束
    connection_status 0
    2、点击浏览器“停止”按钮
    connection_status 1
    3、超时
    connection_status 2注意程序一定要有输出,否则ABORTED状态是检测不到的******你的程序中有set_time_limit(0);和while (true)
    所以程序不会超时和自然结束而使用connection_status()的地方不对至于ignore_user_abort函数,因没有测试,不好乱说
      

  2.   

    又做了一下测试,是可以出现
    connection_status 3
    connection_aborted 1
    这样的结果的:虽然点击了“停止”按钮,但程序仍然运行到超时<?php
    function foo() {
      $s = "\r\nconnection_status " . connection_status();
      $s .= "\r\nconnection_aborted " . connection_aborted();
      file_put_contents('__.txt', $s, FILE_APPEND);

    register_shutdown_function('foo');file_put_contents('__.txt', '');ignore_user_abort(true);
    set_time_limit(10);for($i=0; $i<100000000; $i++) {
      echo $i;
    //  if(connection_aborted()) foo();
    }
    ?>
      

  3.   

    to :xuzuning(唠叨)没发财,我还穷着呢,呵呵。我的意思不是这样的,看下面的这段话,我是从某一版手册中看到的:
    =============================================
    carlos at fischerinformatica dot com dot br
    31-Jan-2002 10:58 
    Very very useful!
    I was building a chat and I wanted my script to detect when the browser was closed, so the user could be deleted from the online_users table.<?
    echo str_repeat(" ",300);
    ignore_user_abort(true); //this way, the user can stop the output, but not the script.
    while (true) {
             echo "test<br>\n";
             flush();
             sleep(2);
             if (connection_status()!=0){
                     include ('dbconnect.inc');
                     $sql="delete from online_users where online_user=$user";
                     $sql_exec=pg_exec($vChatDB, $sql);
                     die(); //kills the script
             }
    }
    ?> 
    ================================================
    他意思好像应该是说,这个程序运行永不过期,只要用户不关闭页面,页面就在后台一直得跑,用户关闭浏览器的时候,是否停止正在跑得php,是靠ignore_user_abort(true);设置的,但是我我怎么设置它都还在后台跑,怎么设置都不停。我测试的时候是php4.4.*
      

  4.   

    to: mynamesucks(肖申克的救赎) 
    你的php是什么版本的?配置文件有没有改过什么特殊的配置?
      

  5.   

    我是5.1.2的
    phpini没改过啥,就加了一些常用扩展,还有程序超时时间改的很长
      

  6.   

    再顶,谁帮我在php 4.*.*上试验一下,然后留下版本号