• <bdo id='A6ZJj'></bdo><ul id='A6ZJj'></ul>

        <tfoot id='A6ZJj'></tfoot>
      1. <i id='A6ZJj'><tr id='A6ZJj'><dt id='A6ZJj'><q id='A6ZJj'><span id='A6ZJj'><b id='A6ZJj'><form id='A6ZJj'><ins id='A6ZJj'></ins><ul id='A6ZJj'></ul><sub id='A6ZJj'></sub></form><legend id='A6ZJj'></legend><bdo id='A6ZJj'><pre id='A6ZJj'><center id='A6ZJj'></center></pre></bdo></b><th id='A6ZJj'></th></span></q></dt></tr></i><div id='A6ZJj'><tfoot id='A6ZJj'></tfoot><dl id='A6ZJj'><fieldset id='A6ZJj'></fieldset></dl></div>

        <small id='A6ZJj'></small><noframes id='A6ZJj'>

      2. <legend id='A6ZJj'><style id='A6ZJj'><dir id='A6ZJj'><q id='A6ZJj'></q></dir></style></legend>
      3. 用户离开页面后 php 执行是否停止?

        时间:2023-08-19
        1. <small id='gt9kw'></small><noframes id='gt9kw'>

        2. <i id='gt9kw'><tr id='gt9kw'><dt id='gt9kw'><q id='gt9kw'><span id='gt9kw'><b id='gt9kw'><form id='gt9kw'><ins id='gt9kw'></ins><ul id='gt9kw'></ul><sub id='gt9kw'></sub></form><legend id='gt9kw'></legend><bdo id='gt9kw'><pre id='gt9kw'><center id='gt9kw'></center></pre></bdo></b><th id='gt9kw'></th></span></q></dt></tr></i><div id='gt9kw'><tfoot id='gt9kw'></tfoot><dl id='gt9kw'><fieldset id='gt9kw'></fieldset></dl></div>
            <tbody id='gt9kw'></tbody>
        3. <legend id='gt9kw'><style id='gt9kw'><dir id='gt9kw'><q id='gt9kw'></q></dir></style></legend>

              <bdo id='gt9kw'></bdo><ul id='gt9kw'></ul>
              <tfoot id='gt9kw'></tfoot>

                  本文介绍了用户离开页面后 php 执行是否停止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想根据一些表单输入运行一个相对耗时的脚本,但我不想求助于 cron,所以我想知道通过 ajax 请求的 php 页面是否会继续执行直到完成,或者是否会如果用户离开页面,则暂停.

                  I want to run a relatively time consuming script based on some form input, but I'd rather not resort to cron, so I'm wondering if a php page requested through ajax will continue to execute until completion or if it will halt if the user leaves the page.

                  在文件末尾的 json_encode 之前,它实际上不会输出到浏览器,那么之前的所有内容还会执行吗?

                  It doesn't actually output to the browser until a json_encode at the end of the file, so would everything before that still execute?

                  推荐答案

                  视情况而定.

                  来自 http://us3.php.net/manual/en/features.connection-handling.php:

                  当 PHP 脚本正常运行时正常状态,是活动的.如果远程客户端断开 ABORTED状态标志打开.一个遥控器客户端断开连接通常是由用户点击了他的停止按钮.

                  When a PHP script is running normally the NORMAL state, is active. If the remote client disconnects the ABORTED state flag is turned on. A remote client disconnect is usually caused by the user hitting his STOP button.

                  您可以决定是否要客户端断开连接导致您要中止的脚本.有时是总是让你的脚本运行很方便即使没有完成接收输出的远程浏览器.然而,默认行为是您的脚本将在远程客户端断开连接.这行为可以通过ignore_user_abort php.ini 指令为以及通过相应的php_value ignore_user_abort Apachehttpd.conf 指令或使用ignore_user_abort() 函数.

                  You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php.ini directive as well as through the corresponding php_value ignore_user_abort Apache httpd.conf directive or with the ignore_user_abort() function.

                  这似乎是说您的问题的答案是是的,如果用户离开页面,脚本将终止".

                  That would seem to say the answer to your question is "Yes, the script will terminate if the user leaves the page".

                  但是要意识到,取决于所使用的后端 SAPI(例如,mod_php),php 无法检测到客户端已中止连接,直到尝试向客户端发送信息.如果您长时间运行的脚本没有发出 flush() 脚本可能会继续运行,即使用户已关闭连接.

                  However realize that depending on the backend SAPI being used (eg, mod_php), php cannot detect that the client has aborted the connection until an attempt is made to send information to the client. If your long running script does not issue a flush() the script may keep on running even though the user has closed the connection.

                  即使您确实定期调用flush(),但具有输出缓冲 on 将导致这些调用陷入陷阱,并且在脚本完成之前不会将它们发送到客户端!

                  Complicating things is even if you do issue periodic calls to flush(), having output buffering on will cause those calls to trap and won't send them down to the client until the script completes anyway!

                  更复杂的事情是,如果您安装了缓冲响应的 Apache 处理程序(例如 mod_gzip),那么 php 将再次检测到连接已关闭并且脚本将继续运输.

                  Further complicating things is if you have installed Apache handlers that buffer the response (for example mod_gzip) then once again php will not detect that the connection is closed and the script will keep on trucking.

                  呸.

                  这篇关于用户离开页面后 php 执行是否停止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <tbody id='HwDKV'></tbody>

                    <legend id='HwDKV'><style id='HwDKV'><dir id='HwDKV'><q id='HwDKV'></q></dir></style></legend>

                    1. <i id='HwDKV'><tr id='HwDKV'><dt id='HwDKV'><q id='HwDKV'><span id='HwDKV'><b id='HwDKV'><form id='HwDKV'><ins id='HwDKV'></ins><ul id='HwDKV'></ul><sub id='HwDKV'></sub></form><legend id='HwDKV'></legend><bdo id='HwDKV'><pre id='HwDKV'><center id='HwDKV'></center></pre></bdo></b><th id='HwDKV'></th></span></q></dt></tr></i><div id='HwDKV'><tfoot id='HwDKV'></tfoot><dl id='HwDKV'><fieldset id='HwDKV'></fieldset></dl></div>
                        <bdo id='HwDKV'></bdo><ul id='HwDKV'></ul>
                      • <small id='HwDKV'></small><noframes id='HwDKV'>

                        <tfoot id='HwDKV'></tfoot>