我有几个负责在服务器上执行GCM操作的PHP文件,当它们想要时它们似乎工作得很好,但它们经常返回一个错误,其中包含以下信息:
Curl错误: 操作在0毫秒后超时,收到0个字节的数据
这是服务器的问题还是我的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, 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;
?>