dongxian7489
2011-10-27 16:17 阅读 41
已采纳

我们可以在任何代码行上使用ignore_user_abort()吗?

Can we use ignore_user_abort on any line of PHP like:

<?php
// Process Codes
if($_GET['nonstop']) {
    ignore_user_abort(1);
    // Background process
}else{
     // Nonbackground process
}
// Other Codes
?>

Or we need to use on only after <?php (first line)?

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    douang1243 douang1243 2011-10-27 16:21

    You are able to use it anywhere you want within your code.

    Die & Exit

    ignore_user_abort() doesn't disable die or exit. It just tells PHP (and the server) to NOT abort the script when the remote users' connection closes.

    Worth Noting

    "PHP will not detect that the user has aborted the connection until an attempt is made to send information to the client. Simply using an echo statement does not guarantee that information is sent, see flush(). " - PHP.Net

    点赞 评论 复制链接分享
  • douzhan5058 douzhan5058 2011-10-27 16:21

    It is a PHP function... it needs to be within a <?php ?> block.

    If it isn't clear, you can have multiple PHP blocks. You can always stick at the top of your page (and you probably should, if this is the behavior you want!).

    点赞 评论 复制链接分享

相关推荐