【问题标题】:PHP Background job not displaying resultsPHP后台作业不显示结果
【发布时间】:2013-02-26 08:18:47
【问题描述】:

我对如何使用 PHP 创建在后台运行的作业进行了大量研究。

 <?php
   ignore_user_abort(true); // run script in background 
   set_time_limit(0); // run script forever 

   // get the size of the output
   ob_start();
   include_once '';//many includes
   //$contentLength = ob_get_length();
   // these headers tell the browser to close the connection
   // once all content has been transmitted
   //header("Content-Length: $contentLength");
   header('Connection: close');
  // flush all output
  ob_end_flush();
  ob_flush();
  flush();

  // close current session
  if (session_id()) session_write_close();


 //lot of code, fetch query from DB with millions records and do calculations

  ?>

当我使用 header("Content-Length: $contentLength");该脚本不返回任何内容。当我评论它时,我得到了数千个使用限制的结果。如果我想检索所有数百万服务器在 3-4 分钟后停止响应

我只需要获得一份庞大的统计报告,不想让用户收到消息 达到最大执行时间。我不想提高时间执行限制,因为限制是未知的。最多可能需要一个小时。我需要它在后台运行。

【问题讨论】:

    标签: php background jobs


    【解决方案1】:

    我的方法是在 sn-ps 中处理报告,即当时 10000 行。将每个计算的部分保存为一个文件,然后在输出之前合并所有文件。 您需要通过 Ajax 调用处理/创建 sn-ps 功能。这样,您可以创建一种用户体验,但在服务器上创建多个任务。然后,您还可以显示进度,以便用户知道发生了什么,您还可以检查它是否跌倒。

    【讨论】:

    • 是的,这有帮助。不错的方法
    猜你喜欢
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 2012-11-22
    • 2010-12-11
    相关资源
    最近更新 更多