加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – GCM卷曲操作超时

发布时间:2020-12-13 15:57:17 所属栏目:PHP教程 来源:网络整理
导读:我有几个php文件负责存储在我的服务器上的GCM操作,他们似乎在他们想要的时候工作得很好,但是他们经常会返回一个错误,指出: Curl error: Operation timed out after 0 milliseconds with 0 out of 0 bytes received 这是服务器的问题还是我的GCM代码有问题?
我有几个php文件负责存储在我的服务器上的GCM操作,他们似乎在他们想要的时候工作得很好,但是他们经常会返回一个错误,指出:

Curl error: Operation timed out after 0 milliseconds with 0 out of 0
bytes received

这是服务器的问题还是我的GCM代码有问题?下面是我的php文件:

<?php

$message = urldecode($_POST['message']);
$order = urldecode($_POST['order']);
$registrationIDs = urldecode($_POST['registrationIDs']);
$apiKey = "API_KEY";
$tableID = urldecode($_POST['tableID']);

$url = 'https://android.googleapis.com/gcm/send';

$fields = array(
    'registration_ids' => array($registrationIDs),'data' => array(
        'message' => $message,'tableID' => $tableID,'order' => $order
    ),);

$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,CURLOPT_SSL_VERIFYPEER,false);

curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));



// Execute post
$result = curl_exec($ch);
if(curl_errno($ch)) {
    echo 'Curl error: ' . curl_error($ch);
}

// Close connection
curl_close($ch);

echo $result;

?>

解决方法

我试图使用您的代码发送推送通知,我已经实现了它.

For tests I recommend you to set the “dry_run” param. You will be sending messages to GCM and it will return it to you as a “fake” response.

现在你的问题,我已经搜索了可能发生的事情,因为看起来你有一个卷曲限制或什么,但我不是这个主题的专家所以这里有一些你可以尝试的提示:

>如果您通过浏览器运行脚本,则将set_time_limit设置为零,持续无限秒.

参数或者set_time_limit(0);
>使用此选项’CURLOPT_TIMEOUT’增加卷曲的操作时间限制

curl_setopt($ch,CURLOPT_TIMEOUT,20); // 20秒
>从服务器进行无限重定向也会发生这种情况.要暂停此操作,请尝试在禁用后续位置的情况下运行脚本.

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读