douhan8892 2015-12-26 23:17
浏览 227

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

I have a php page that runs a series of queries and loops as shown below, but I am getting a 500 Internal Server Error which I can only assume is down to a timing out.

The main loop should loop through about 3000 records but I have added the if statement to check if it works with a lower number which it does (the userIDs are 1, 2, 3, 4 etc and therefore indicate the number of records being looped through). Up this number to 2000 and I get the error after about 1 minute.

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
        ....
    }
}

I have tried setting the max_execution_time and have put set_time_limit(0); at the beginning of any loop but this does not seem to help. I can't find any errors in any of logs relating to the error.

Also, it is not an issue with the data as if I try:

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

it all works. But try:

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

if fails.

Any thoughts?

  • 写回答

2条回答 默认 最新

  • douxi1968 2015-12-26 23:52
    关注

    As a DBA I belive it to be wise to move some of the logic to the SQL instead. Since you don't specify the rest of the queries the best option could be:

    SELECT DISTINCT userID FROM tblResults where userID < 500
    

    Combine this with the rest of your queries I bet the execution time should decrease. Since > 1 minute execution for 2000 iterations seems a bit long, suggesting you have some nasty stuff going on in that loop :)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog