title: PHP-FPM served by Nginx: 504 Gateway Time-out - nginx
body: <p>I have a PHP Android Push notification script. when I run the script I get the following response "504 Gateway Time-out nginx" in my browser.
  On my server in the general log overview I get the following error: </p>
  
  <blockquote>
    <p>Error: 504, Message: GET /gcm_test.php HTTP/1.1, Source: nginx SSL
    access</p>
  </blockquote>
  
  <p>On my server in the proxy_error_log I get the following error:</p>
  
  <blockquote>
    <p>2016/07/25 08:18:19 [error] 23882#0: *4375 upstream timed out (110:
    Connection timed out) while reading response header from upstream,
    client: 12.34.567.891, server: website.com, request: "GET
    /gcm_test.php HTTP/1.1", upstream:
    "fastcgi://unix:///var/www/vhosts/system/website.com/php-fpm.sock",
    host: "www.website.com"</p>
  </blockquote>
  
  <p>The Android Push PHP script:</p>
  
  <pre><code>&lt;?php
      // Replace with the real server API key from Google APIs
      $apiKey = "my apikey";
  
      // Replace with the real client registration IDs
      $registrationIDs = array("red id1", "reg id2");
  
      // Message to be sent
      $message = "Your message e.g. the title of post";
  
      // Set POST variables
      $url = 'https://gcm-http.googleapis.com/gcm/send';
  
      $fields = array(
          'registration_ids' =&gt; $registrationIDs,
          'data' =&gt; array( "message" =&gt; $message ),
      );
      $headers = array(
          'Authorization: key=' . $apiKey,
          'Content-Type: application/json'
      );
  
      // Open connection
      $ch = curl_init();
  
      // Set the URL, number of POST vars, POST data
      curl_setopt( $ch, CURLOPT_URL, $url);
      curl_setopt( $ch, CURLOPT_POST, true);
      curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
      //curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields));
  
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));
  
      // Execute post
      $result = curl_exec($ch);
  
      // Close connection
      curl_close($ch);
      // print the result if you really need to print else neglate this
      echo $result;
  ?&gt;
  </code></pre>
  
  <p>If I replace the line "$result = curl_exec($ch);" with "echo "End of script";" I get no errors and the result is "End of script".
  So it looks like the problem is in the line "$result = curl_exec($ch);"</p>
  
  <p>I also tried the following, <a href="https://kb.plesk.com/en/120210" rel="nofollow">PLESK nginx 504 error: Gateway Timeout</a> with no luck.</p>
  
  <p>On my sever I'm running PHP7.0.4 as FPM application served by nginx</p>
  
  <p>Someone any ideas?
  Thanks!</p>