0

It's strange problem, I apologize for I really can't explain what kind of problem it is.

I can just say what it happen.

I have a php file, it print the html page, I can't copy whole of my code, it's too long, So I just typo a simple version

<html>
// ... some code

$count = 0;
$query = $mysql->query($sql);
while($row = $mysql->fetch_array($query)) {
    // ... some php code

    echo "<div id='id{$count}'>.....lots of html code and some php variable </div>"  // it is a long html code

    echo "<ul id='ul{$count}'> ..... almost the same as above, lost html </ul>"

    echo ...
    echo ...

    // ... some php code

    $count++;

}

// ... lots of other code
</html>

Normally, It's not any problem, but this time, it will read about 800 record in the loop, then, it can only load about 80.

I think maybe some error occur, so I try to print something in the loop, then something strange happened.

I add this
var_dump("!@#!@#!@#!@#");
Then, I refresh page, now it can load 96 record (I refresh page serval times, always 96)

Then I change it to var_dump("!@#!@#!@#!@#$$$$$");
Now it can load 257 record

after that, I try to change the string that I print, very times I change it, the number of record will change, until I use this:var_dump("!@#!@#!@#!@#!@#!@#!@#!@#", $count);. whole page could be loaded.

afraid.jpg
  • 449
  • 1
  • 5
  • 17
  • 1
    SO have you looked at your PHP Error log? Your MySQL Error log? or your APache errror log??? – RiggsFolly Feb 18 '20 at 09:45
  • Are you using the `mysql_` or the `mysqli_` or the PDO database extension?? – RiggsFolly Feb 18 '20 at 09:46
  • I would start splitting the logic from the view rendering. This will help you to understand where is the error; in the logic calculation or during the rendering. After that, it would be a matter of debugging and checking the error logs. – Chemaclass Feb 18 '20 at 09:47
  • To quote the Floyd, "Is there anybody out there?" – RiggsFolly Feb 18 '20 at 09:54
  • @RiggsFolly this project is base on php5.6 and `mysql_`. – afraid.jpg Feb 18 '20 at 10:10
  • @Chemaclass It is an old project... I just charge this code half years, so there are lots of historical reasons that I can't rebuild this code, I just check nginx error log, there no something useful info, and It is also no problem with mysql log. but php error log, It wasn't be log, It check the php.ini... error_log setting was not open – afraid.jpg Feb 18 '20 at 10:12
  • Maybe it makes sense to refactor the loop part (where you fetch the values from the DB). Because we don't know if it's a problem while fetching the data from the DB (do you get all the 800 records from the DB?) or some problem while rendering or `counting++`. – Chemaclass Feb 18 '20 at 10:22
  • Another interesting question, where do you place this code: `var_dump("!@#!@#!@#!@#")`? before, during or after the looping? – Chemaclass Feb 18 '20 at 10:24
  • Your process is too much, so It may be about the PHP config => maximum memory OR maximum execution time. – Amin Shojaei Feb 18 '20 at 10:39
  • @afraid.jpg you need to debug and trace your code better – Amin Shojaei Feb 18 '20 at 10:41
  • @Chemaclass I try to add `var_dump` before, during and after the loop separately, It could show when adding before loop, and show (with strange) during loop, but when I tried to print string after loop, nothing shown. So I think something break the loop, maybe as the answer said, some php setting or nginx setting cause this. I will try it – afraid.jpg Feb 18 '20 at 10:55

1 Answers1

3

Some debugging tips:

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

It totally seems that you are reaching some size limits, and script execution (or data handling) stops at one point, which is reached at 69 - or outputting more chars per record - at 257 records.

Maybe

I don't think it's about the number of queries or such, but the the mass of output you generate. Otherwise it would not make any difference how big your var_dump dummy is.

Paflow
  • 1,581
  • 19
  • 43
  • great! **there is is a limit set for PHPs output buffering which causes problems.** this tip help me, I don't know where I can modify the config of fastcgi, but I found another answer here https://stackoverflow.com/q/12165810/8654320, I add the header at the top of my php code, it works – afraid.jpg Feb 19 '20 at 07:08
  • yep, you can edit your answer with the link I found, I will mark this answer – afraid.jpg Feb 19 '20 at 13:47