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:
Error: 504, Message: GET /gcm_test.php HTTP/1.1, Source: nginx SSL access
On my server in the proxy_error_log I get the following error:
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"
The Android Push PHP script:
<?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' => $registrationIDs,
'data' => array( "message" => $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;
?>
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);"
I also tried the following, PLESK nginx 504 error: Gateway Timeout with no luck.
On my sever I'm running PHP7.0.4 as FPM application served by nginx
Someone any ideas? Thanks!