function fun(){
fopen('./为什么又是放两天假呢.txt', 'a+');
}
ignore_user_abort(false);
register_shutdown_function('fun', '');
sleep(5);问题1:
ignore_user_abort 的参数无论是true或者false到最好都会创建那个txt文件问题2:
创建的文件并没有在我想要的目录下,而是在apache根目录下
哪位帮忙解释下?

解决方案 »

  1.   

    问题1 不敢确定 但是印象中好像很多服务架构里,包括php-fpm等,即使用户关闭浏览器,处理进程也不会收到这一信号 因此脚本会继续执行直到它完成
    问题2 不熟悉apache 请无视我 
      

  2.   

    转手册上两句话
    1、register_shutdown_function: Registers the function named by function to be executed when script processing is complete. 
    2、Note: Working directory of the script can change inside the shutdown function under some web servers, e.g. Apache. 
      

  3.   

    ignore_user_abort 只是设置是否在客户端断开时继续执行程序,默认是 0,即不继续执行
    register_shutdown_function 是注册一个当程序结束时必须执行的函数对于你的代码,只要程序结束了就会创建那个txt文件
    至于是程序自然结束还是客户端断开而结束或者是因其他原因结束(比如超时),你的程序并没有做出相应的动作。