500内部服务器错误 - 由于超时?

时间:2015-12-26 23:17:01

标签: php

我有一个运行一系列查询和循环的php页面,如下所示,但是我得到一个500 Internal Server Error,我只能假设它已经超时了。

主循环应该遍历大约3000条记录,但我添加了 if 语句来检查它是否与较低的数字一起工作(用户ID是1,2,3,4等因此表明循环的记录数量)。将此数字增加到2000,我在大约1分钟后得到错误。

ini_set('max_execution_time', 9000); 
...
$sqlSelect = "SELECT DISTINCT userID FROM tblResults;";
$selectedIDs = mysql_query($sqlSelect);

while($resultRow = mysql_fetch_array($selectedIDs)) {
    $userID = $resultRow['userID'];
    set_time_limit(0);

    if ($userID < 500) {
        ....
        series of queries and loops
        ....
    }
}

我已尝试设置 max_execution_time 并在任何循环开始时放置 set_time_limit(0); ,但这似乎没有帮助。我无法在与错误相关的任何日志中发现任何错误。

此外,数据不是问题,就像我尝试一样:

    if ($userID >= 500 && $userID < 1000) 
    if ($userID >= 1000 && $userID < 1500) 
    if ($userID >= 1500 && $userID < 2000)   etc 

一切正常。但试试:

    if ($userID < 2000) [ie the same data but all at once]

如果失败。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

作为一名DBA,我认为将一些逻辑转移到SQL是明智的。由于您未指定其余查询,因此最佳选项可能是:

SELECT DISTINCT userID FROM tblResults where userID < 500

将此与其他查询相结合我敢打赌,执行时间应该减少。由于&gt; 2000次迭代的1分钟执行似乎有点长,这表明你在这个循环中有一些讨厌的东西:)

答案 1 :(得分:0)

您是否尝试运行此代码?

while($resultRow = mysql_fetch_object($selectedIDs)) {
        $userID = $resultRow->UserID;

        if ($userID < 500) {
            ....
            series of queries and loops
            ....
        }
    }
相关问题