Roots Discourse

Assigning a variable breaks the server

hello peeps,

something weird happens to my code.
I need to declare a class conditionally, BUT, if I try doing it, this makes server crash (Bad Gateway error)

    if( !isset($_GET['t']) ){
        $results = json_decode(Search::getPostBasic(), true);
    else {
        $results = json_decode(Search::getPostAdvanced(), true);
       $results ? $columns = 'card-columns' : $columns = '';
  <div class="row no-gutters masonry mb-5">
    <div class="col-lg-10 mx-auto mb-5 {{$columns}}">

not a rocket science but this crashes the page

any hint???

EDIT: seems to be connected to the json_decode action…

[error] 531#0: *4437 upstream prematurely closed FastCGI stdout while reading response header from upstream, client:, server: ~^(www\.)?(?<domain>.+?)$, request: "GET /?t=a&s=ss HTTP/1.1", upstream: "fastcgi://", host: ""

Edit: json_decode returns NULL for an empty input string (in recent PHP 7.4). Are you correctly handling NULL values, e.g. when iterating over it in a loop in the template?

Is this a staging/production server? It may be a good idea to show a proper server error page to the visitor instead just an empty HTTP 500 header response.

What do these do?

Probably unrelated but I don’t recommend using ternary operators this way. When you use a ternary, you should be using the result, i.e.

$columns = $results ? 'card-coumns' : '';

IMO it’s easier to read and understand.

hei :slight_smile:
@strarsis it’s localhost, running on nginx.
I am just decoding a json!!
if not call json_Decode it works…

Check the PHP error logs, the nginx error log only indicates that PHP had an error. The PHP error log should show the actual error.

they perform two custom queries.

the funny part is that the result is a json from any of those, ok?
if I call json_decode, it crashes, on localhost, nginx…not in production with apache

@strarsis this is the error I get…

But this is the nginx error. Isn’t there a PHP log, too?
upstream is the PHP FastCGI daemon which response nginx passes through.
In this case PHP encountered an error and didn’t give nginx the expected response.

The error can be anywhere here, from some unexpected JSON input string to non-existing variable in a template.

uh ok, don’t have a clue where to look for the log I should inspect then :sweat_smile:

What kind of system is this? Vagrant, Docker container, Trellis staging?

no is a simple localhost managed with brew

Are you using a setup similar or equal to this?:

In any way there is a PHP daemon on your development system that got its own log.
You need to get the log from it to find the exact reason.
This is also the only proper way doing development/debugging. Everything else would be just guessing.

yes it’s something similar (on nginx), the only thing I am missing is where to look for PHP FastCGI daemon log :smiley:

When you can find the httpd/apache logfiles under /var/log/httpd or similar, the php-fpm log files should be found under a similar directory, e.g. /var/log/php-fpm or maybe /var/log/php (without the -fpm).

Edit: Also try out the locate command for a quick-and-dirty system-wide search for these files.

how they are supposed to be called those log files?


When you got console access and can run the php CLI, you should be able to let it print the exact path
(php --info | grep error):

When systemd/journald is used, you have to query the log differently
(journalctl -u nginx -u php-fpm --since today):