我可以在运行SQL查询时让php echo吗?

问题描述

Liquidweb托管我的网站,如果没有向负载均衡器发送信号,它们将执行严格的30秒超时策略。当我直接访问数据库时,我的SQL查询需要大约34秒的时间来处理。

我的php看起来像这样:

echo " "; //To keep the site alive
$results = $this->db->query($sql); //Takes longer than 30 seconds
echo " "; //To keep the site alive.

Liquidweb不能更改30秒的限制,正在查询的DB是具有成千上万行的成员数据库,并且只会变得更大。

当SQL查询在后台运行时,有没有办法让页面向负载均衡器发送信号?

解决方法

您可以将mysql查询请求发送到dev \ null并将数据存储在文件中吗?然后在35s超时后通过Ajax提取文件

例如

    ob_start();
    $size = ob_get_length();
    header("Content-Encoding: none");
    header("Content-Length: {$size}");
    header("HTTP/1.1 200 OK");
    header("Connection: close");
    ob_end_flush();
    ob_flush();
    flush();

    $results = $this->db->query($sql);
    $fo = fopen('path_to_file','a+');
    fwrite($fo,json_encode($result));
    fclose($fo);

超时后,通过AJAX将此文件提取到前端

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...