PHP Android プッシュ通知スクリプトがあります。スクリプトを実行すると、ブラウザに「504 Gateway Time-out nginx」という応答が表示されます。私のサーバーでは、一般的なログの概要で次のエラーが表示されます。
エラー: 504、メッセージ: GET /gcm_test.php HTTP/1.1、ソース: nginx SSL アクセス
サーバーの proxy_error_log に次のエラーが表示されます。
2016/07/25 08:18:19 [エラー] 23882#0: アップストリームからの応答ヘッダーの読み取り中に *4375 アップストリームがタイムアウトしました (110: 接続がタイムアウトしました)、クライアント: 12.34.567.891、サーバー: website.com、リクエスト: "GET /gcm_test.php HTTP/1.1"、アップストリーム: "fastcgi://unix:///var/www/vhosts/system/website.com/php-fpm.sock"、ホスト: "www.website.com "
Android プッシュ PHP スクリプト:
<?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;
?>
「$result = curl_exec($ch);」という行を置き換えると、with "echo "スクリプトの終わり";" エラーは発生せず、結果は「スクリプトの終わり」です。したがって、問題は「$result = curl_exec($ch);」の行にあるようです。
次のPLESK nginx 504 エラーも試しました:運が悪いゲートウェイ タイムアウト。
私のサーバーでは、nginx が提供する FPM アプリケーションとして PHP7.0.4 を実行しています。
誰かアイデアはありますか?ありがとう!