1

我有一个 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 错误:网关超时,没有运气。

在我的服务器上,我将 PHP7.0.4 作为 nginx 服务的 FPM 应用程序运行

有人有什么想法吗?谢谢!

4

1 回答 1

2

看起来你需要增加fastcgi_read_timeout你的 nginx 配置。

于 2016-07-25T07:53:47.403 回答