GCM卷曲操作超时 [英] GCM curl operation time out
问题描述
我有一对夫妇的PHP文件负责存储在我的服务器上GCM操作,他们似乎当他们想,但他们往往返回一条错误的工作就好了:
卷曲的错误:操作超时后0毫秒0出0 接收的字节数
难道这是与服务器或与我GCM code的一个问题一个问题吗?下面是我的PHP文件:
< PHP
$消息= urlde code($ _ POST ['消息']);
$为了= urlde code($ _ POST ['秩序']);
$ registrationIDs = urlde code($ _ POST ['registrationIDs']);
$ apiKey =API_KEY;
$ TABLEID = urlde code($ _ POST ['TABLEID']);
$ URL ='https://android.googleapis.com/gcm/send';
$领域=阵列(
registration_ids'=>数组($ registrationIDs)
'数据'=>阵列(
'信息'=> $消息,
TABLEID'=> $ TABLEID,
为了'=> $订单
),
);
$标题=阵列(
授权:键='。 $ apiKey,
内容类型:应用程序/ JSON
);
//打开连接
$ CH = curl_init();
//设置URL,POST数瓦尔,POST数据
curl_setopt($ CH,CURLOPT_URL,$网址);
curl_setopt($ CH,CURLOPT_POST,真正的);
curl_setopt($ CH,CURLOPT_HTTPHEADER,$头);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,真正的);
curl_setopt($ CH,CURLOPT_SSL_VERIFYPEER,假);
curl_setopt($ CH,CURLOPT_POSTFIELDS,json_en code($域));
//执行后
$结果= curl_exec($ CH);
如果(curl_errno($ CH)){
回声卷曲的错误:。 curl_error($ CH);
}
//关闭连接
curl_close($ CH);
回声$结果;
?>
我已经尝试使用code发送推送通知,我已经做到了这一点。
有关测试,我建议你设置了dry_run参数。你会发送消息到GCM,它会返回给你作为一个假的回应。
现在你的问题,我已搜查会发生什么,因为它似乎你有一个卷曲的限制或东西,但我不是这个主题的专家,所以这里有一些提示,你可以尝试:
-
如果您运行的是通过浏览器的脚本,然后设置参数或者set_time_limit为无限秒零。
参数或者set_time_limit(0)
-
增加使用该选项卷曲的操作时间限制CURLOPT_TIMEOUT
curl_setopt($ CH,CURLOPT_TIMEOUT,20);
//20秒 -
它也可以发生从服务器无限的重定向。为了制止这种,尝试运行与后续的位置禁用脚本。
curl_setopt($ CH,CURLOPT_FOLLOWLOCATION,假);
I have a couple of php files responsible for GCM operations stored on my server, they seem to work just fine when they want to but they often return an error that states:
Curl error: Operation timed out after 0 milliseconds with 0 out of 0 bytes received
Is this is a problem with the server or a problem with my GCM code? Below is my php file:
<?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, true);
curl_setopt($ch, 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;
?>
I have tried to send a Push notification using your code and I have achieved it.
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.
Now your problem, I have searched what could happen because it seems that you have a curl limitation or something but I am not expert of this theme so here are some tips that you can try:
If you are running the script through browser, then set the set_time_limit to zero for infinite seconds.
set_time_limit(0);
Increase the curl's operation time limit using this option 'CURLOPT_TIMEOUT'
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
// 20 secondsIt can also happen for infinite redirection from the server. To halt this, try to run the script with follow location disabled.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
这篇关于GCM卷曲操作超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!