0

yesterday I stumbled across a weird problem. Suddenly a specific PHP script didn't work anymore, it threw a 502 error. When I enabled error_reporting, only notices / warnings are displayed, but the rest of the page is being rendered correctly. When I disable error_reporting("E_ALL"); ini_set("display_errors", 1); again, NGINX throws 502 again.

The weird thing is, when I catch the notices / warnings with the following snippet:

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    if ($errno == E_USER_NOTICE){
    }
}

set_error_handler("myErrorHandler");

the page renders correctly aswell, obviously without showing the errors.

Debian version: 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64

PHP version: php7.4-fpm

NGINX version: nginx/1.10.3

Could this be a memory issue? Or has someone another explanation, why this is happening?

The code doesn't set the response header since I never set any headers somewhere. I also don't use a error handler, I just activate error_reporting, when something doesn't work. If everything works, I disable display_errors, so then notices / warnings won't be shown.

If I remove the following line of my file, it also works without catching the errors: $list = $tn->getMassnahmen();

$tn is an instance of my class 'teilnehmer': $tn = new teilnehmer;

Code of 'getMassnahmen':

    function getMassnahmen()
    {
        $stmt = $this->db->prepare('SELECT * FROM `massnahmen_txt` ORDER BY `id` ASC');
        if ($stmt->execute()) {
            while ($row = $stmt->fetch()) {
                $result[] = $row;
            }
        }

        return $result;
    }

'teilnehmer' are my clients. Clients can have files added to them (different database table). The error somehow only occurs, if clients have files added. If I comment out the whole section regarding files in my code, the error still occurs. Only the removing of the line $list = $tn->getMassnahmen(); will help. But this line DOES NOT have anything to do with the files in any way. They only use the same class.

The class / instance of 'teilnehmer' ($tn) is being used multiple times before in the code, without any errors.

Error Log:

Notice:  Undefined variable: nocal in /PATH//html/inc/global.inc.php on line 34
Notice:  Undefined variable: result in /PATH//html/classes/user.php on line 672
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/inc/global.inc.php on line 57
Notice:  Undefined variable: newdates in /PATH//html/inc/global.inc.php on line 101
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/inc/global.inc.php on line 101
Notice:  Undefined variable: list in /PATH//html/inc/global.inc.php on line 113
Notice:  Undefined variable: is_index in /PATH//html/inc/global.inc.php on line 120
Notice:  Undefined variable: result in /PATH//html/classes/user.php on line 898
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/inc/global.inc.php on line 129
Notice:  Undefined variable: calendar in /PATH//html/inc/global.inc.php on line 133
Notice:  Undefined variable: result in /PATH//html/classes/user.php on line 898
Notice:  Undefined variable: result in /PATH//html/classes/mandanten.php on line 48
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/inc/global.inc.php on line 144
Notice:  Undefined variable: result in /PATH//html/classes/user.php on line 1425
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/inc/global.inc.php on line 190
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Warning:  array_walk() expects parameter 2 to be a valid callback, class 'user' does not have a method 'htmlspecialcharsArray' in /PATH//html/classes/user.php on line 224
Notice:  Undefined index: success in /PATH//html/teilnehmer_edit.php on line 17
Notice:  Undefined index: removedfile in /PATH//html/teilnehmer_edit.php on line 21
Notice:  Undefined index: successremovelog in /PATH//html/teilnehmer_edit.php on line 26
Notice:  Undefined index: fehltag_add in /PATH//html/teilnehmer_edit.php on line 65
Notice:  Undefined index: remove_fehltag in /PATH//html/teilnehmer_edit.php on line 142
Notice:  Undefined variable: content in /PATH//html/teilnehmer_edit.php on line 248
Notice:  Undefined variable: active_fehltage in /PATH//html/teilnehmer_edit.php on line 257
Notice:  Undefined variable: kursdata in /PATH//html/teilnehmer_edit.php on line 281
Notice:  Undefined variable: statusdata in /PATH//html/teilnehmer_edit.php on line 282
Notice:  Undefined variable: tabledata in /PATH//html/classes/template.php on line 134
Notice:  Undefined variable: result in /PATH//html/classes/teilnehmer.php on line 606
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/teilnehmer_edit.php on line 300
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/teilnehmer_edit.php on line 314
Notice:  Undefined variable: filelist in /PATH//html/teilnehmer_edit.php on line 387
Notice:  Undefined variable: fehlliste in /PATH//html/teilnehmer_edit.php on line 676
Notice:  Trying to access array offset on value of type bool in /PATH//html/teilnehmer_edit.php on line 699
Notice:  Undefined variable: aglist in /PATH//html/teilnehmer_edit.php on line 740
Notice:  Undefined index: name in /PATH//html/teilnehmer_edit.php on line 742
Notice:  Undefined index: name in /PATH//html/teilnehmer_edit.php on line 742
Notice:  Undefined variable: result in /PATH//html/classes/teilnehmer.php on line 684
Warning:  sizeof(): Parameter must be an array or an object that implements Countable in /PATH//html/teilnehmer_edit.php on line 752
Notice:  Undefined variable: list1 in /PATH//html/teilnehmer_edit.php on line 776
Notice:  Undefined variable: mlist in /PATH//html/teilnehmer_edit.php on line 796

Thanks in advance for your help!

Chris
  • 21
  • 2
  • We need some more info/code to answer this fully. it might be your default error handler, it might be that somehwere in the code the response header is set to 503. please provide more info – YouriKoeman Jun 06 '20 at 13:12
  • I've edited my main post. Thanks! – Chris Jun 06 '20 at 13:32
  • one last thing that would be of great help, can you print the errors when you catch them with your snippet? maybe those will have good information in them. – YouriKoeman Jun 06 '20 at 13:35
  • I've added the error log to the main post. Additionally I've corrected the errorcode. NGINX throws 502 instead of 503. – Chris Jun 06 '20 at 13:54
  • What i suspect is a timeout taking place, can you set `set_time_limit(0)` and in nginx configure the timout to something high. – YouriKoeman Jun 06 '20 at 13:58
  • I think I've just found the error in the NGINX error log: `2020/06/06 16:00:39 [error] 932#932: *7874 upstream sent too big header while reading response header from upstream, ` Are those PHP notices / warnings sent via header aswell or what could cause this? – Chris Jun 06 '20 at 14:03
  • What that means is that the returned response is too big for the fastcgi buffer, that can definitely be the problem. just bumb up the buffer sizes – YouriKoeman Jun 06 '20 at 14:05
  • more about it here https://gist.github.com/magnetikonline/11312172#determine-fastcgi-response-sizes – YouriKoeman Jun 06 '20 at 14:06
  • This did it! Thanks alot! – Chris Jun 06 '20 at 14:13

1 Answers1

0

After setting

fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;

in my nginx configuration the issue is resolved. Seems like the buffer size for fastcgi wasn't big enough for the response. Thanks a lot for your help!

Chris
  • 21
  • 2