WebApps:处理大量数据时避免超时

发布于 2024-07-25 18:01:39 字数 89 浏览 1 评论 0原文

在 Web 应用程序中,如何处理通常会导致超时的大量数据? 例如。 处理数据库以输出大型报告? 我通常使用 PHP/Zend Framework/MySQL。

in web applications, how do i handle processing of large amounts of data that usually cause timeouts? eg. processing a db to output a large report? i usually use PHP/Zend Framework/MySQL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

半仙 2024-08-01 18:01:39

各种异步机制。 例如,在作业表中对作业进行排队,并让后台的自动化任务按固定计划轮询表中是否有新添加的作业、处理它们,并以某种方式通知用户它已完成。

在最近的一款应用程序中,用户必须生成的文档实际上是在一页中请求的。 这简单地解释为将一行插入到作业表中。 一个事件定期运行,执行在第二个表中“组成”文档数据所需的所有 SQL,第三步是显示待处理/已完成文档的 PHP 页面。 在这种情况下,没有真正的周转要求,因此人们不会通过电子邮件或任何此类机制主动通知,但很容易将其分层。

有一百万种方法可以剥这只猫的皮……

Asynchronous mechanisms of various sorts. For example, queue up the job in a job table and have an automated task in the background poll the table on a fixed schedule for newly-added jobs, process them, and somehow notify the user it has been done.

In one recent app, a document users must generate is actually requested in one page. This simply translates into the fact that a row is inserted into a job table. An event runs periodically, which performs all the SQL necessary to "compose" the document's data in a second table, and a third step is a PHP page that shows pending/completed documents. In this case, there is no real turnaround requirement, so people aren't actively notified via email or any such mechanism, but it'd be easy to layer that over it all.

There's a million ways to skin this cat...

×眷恋的温暖 2024-08-01 18:01:39

我通常会异步执行任务 - 我认为你可以在 PHP 中使用类似的东西:

exec ("/usr/local/bin/php build_report.php")

I'd typically execute the task asynchronously - I think you can use something like this in PHP:

exec ("/usr/local/bin/php build_report.php")
享受孤独 2024-08-01 18:01:39

当服务器端代码处理数据时,客户端需要定期轮询服务器以保持会话活动。 如果您不定期轮询服务器,最终您的 HTTP 会话将过期并导致超时错误。

While the server side code is processing the data the client will need to poll the server periodically to keep their session alive. If you do not poll the server periodically eventually your HTTP session will expire and cause a timeout error.

执妄 2024-08-01 18:01:39

您可以做的一件事是刷新输出缓冲区,然后发送一些 javascript 以在处理过程中更新进度条。 这是一个例子:

<html>
<body>
<div id="progressBar" style="width: 0px; height: 20px; background: #900; color: #fff;">Progress</div>
</body>
</html>
<?

while(@ob_end_flush());

for ($i = 0; $i < 10; $i++) {

    echo "<script type=\"text/javascript\">var pb = document.getElementById('progressBar'); pb.style.width = '" . ($i * 20) . "px';</script>";
    sleep(1);
}

?>

One thing you can do is flush the output buffer, then send some javascript to update a progress bar during your processing. Here's an example:

<html>
<body>
<div id="progressBar" style="width: 0px; height: 20px; background: #900; color: #fff;">Progress</div>
</body>
</html>
<?

while(@ob_end_flush());

for ($i = 0; $i < 10; $i++) {

    echo "<script type=\"text/javascript\">var pb = document.getElementById('progressBar'); pb.style.width = '" . ($i * 20) . "px';</script>";
    sleep(1);
}

?>
白龙吟 2024-08-01 18:01:39

set_time_limit ( int $seconds ) 允许您修改执行时间限制,并且可以在执行完需要较长时间执行的脚本后将其重置回正常状态。

set_time_limit ( int $seconds ) would allow you to modify the time limit for execution and you can reset it back to normal when you are done executing the scripts which would take a longer time to execute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文