• <bdo id='lJO7X'></bdo><ul id='lJO7X'></ul>
    <tfoot id='lJO7X'></tfoot>
  • <legend id='lJO7X'><style id='lJO7X'><dir id='lJO7X'><q id='lJO7X'></q></dir></style></legend>

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

    1. <small id='lJO7X'></small><noframes id='lJO7X'>

      1. 如何在 php 脚本完成之前导致重定向发生?

        时间:2023-11-30
        <tfoot id='ZAWUD'></tfoot>

          1. <small id='ZAWUD'></small><noframes id='ZAWUD'>

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

              1. <legend id='ZAWUD'><style id='ZAWUD'><dir id='ZAWUD'><q id='ZAWUD'></q></dir></style></legend>
                • <bdo id='ZAWUD'></bdo><ul id='ZAWUD'></ul>

                    <tbody id='ZAWUD'></tbody>
                  本文介绍了如何在 php 脚本完成之前导致重定向发生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想运行一个 php 脚本,它会发送一堆电子邮件(新闻通讯),但由于它可能需要一段时间才能运行,所以我希望用户立即被重定向到一个页面,其中包含类似您的新闻通讯是排队等待发送."
                  到目前为止,标头重定向有效,但直到所有电子邮件都发送完毕后才会导致重定向.我可以在发送重定向后关闭连接,以便浏览器立即执行重定向吗?我试过这样的东西

                  I want to run a php script that will send out a bunch of emails (newsletters) but since it can take a while for that to run I want the user be immediately redirected to a page with a message like "Your newsletters are queued to be sent out."
                  So far the header redirects work but they do not cause the redirection until after all the emails get sent. Can I close the connection after sending the redirect so the browser acts on the redirect immediately? I tried stuff like this

                  
                  ob_start();
                  ignore_user_abort(true);
                  header( "refresh:1;url=waitforit.php?msg=Newsletters queued up, will send soon.");
                  header("Connection: close");
                  header("Content-Length: " . mb_strlen($resp));
                  echo $resp;
                  //@ob_end_clean();
                  ob_end_flush();
                  flush();
                  
                  

                  各种排列组合,但无济于事.我怀疑它不能这么简单,但在我开始搞乱 cron 作业或自定义守护进程之前,我想我会研究这种方法.谢谢

                  in various permutations and combinations but to no avail. I suspect it cannot be done so simply but before I start messing with cron jobs or custom daemons I thought I'd look into this approach. Thanks

                  例如像下面建议的blockhead,但没有运气

                  eg like blockhead suggests below, but no luck

                  ob_start();
                  ignore_user_abort(true);
                  header( "refresh:1;url=mailing_done.php?msg=Newsletters queued for sending.");
                  header("Connection: close");
                  header("Content-Length: 0" );
                  //echo $resp;
                  ob_end_flush();
                  flush(); 

                  推荐答案

                  如果你想连续运行脚本并且仍然想显示一些输出那么为什么不使用ajax请求到可以排队邮件的服务器并且仍然让用户继续浏览该页面.

                  If you want to run script continuously and still want to display some output then, why don't you use an ajax request to server which can queue mails and still let user continue browsing that page.

                  如果你不想用这个;相反,您可以使用,即使用户将被重定向到 show_usermessage.php 页面

                  If you don't want to use this; instead you could use, the script runs background even if the user will be redirected to show_usermessage.php page

                  <?PHP
                      //Redirect to another file that shows that mail queued
                      header("Location: show_usermessage.php");
                  
                      //Erase the output buffer
                      ob_end_clean();
                  
                      //Tell the browser that the connection's closed
                      header("Connection: close");
                  
                      //Ignore the user's abort (which we caused with the redirect).
                      ignore_user_abort(true);
                      //Extend time limit to 30 minutes
                      set_time_limit(1800);
                      //Extend memory limit to 10MB
                      ini_set("memory_limit","10M");
                      //Start output buffering again
                      ob_start();
                  
                      //Tell the browser we're serious... there's really
                      //nothing else to receive from this page.
                      header("Content-Length: 0");
                  
                      //Send the output buffer and turn output buffering off.
                      ob_end_flush();
                      flush();
                      //Close the session.
                      session_write_close();
                  
                  
                      //Do some of your work, like the queue can be ran here,
                      //.......
                      //.......
                  ?>
                  

                  这篇关于如何在 php 脚本完成之前导致重定向发生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:.zip 文件的下载运行损坏的文件 php 下一篇:来自 PHP 的 mp4 - 不在 HTML5 视频标签中播放

                  相关文章

                • <tfoot id='F18E1'></tfoot>

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

                  1. <legend id='F18E1'><style id='F18E1'><dir id='F18E1'><q id='F18E1'></q></dir></style></legend>
                      • <bdo id='F18E1'></bdo><ul id='F18E1'></ul>

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