GCM Curl Waiting Time

I have a couple of php files responsible for the GCM operations stored on my server, they seem to work fine when they want, but often return an error that states:

Twisting error: response time after 0 milliseconds from 0 of 0 bytes received

Is this a server problem or a problem with my GCM code? Below is the 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;

?>
+4
source share
1 answer

I tried to send a Push notification using your code, and I reached it.

For tests, I recommend that you set the "dry_run" parameter. You will send messages to GCM and it will return it to you as a "fake" response.

, , , , - , , , :

  • script , set_time_limit .

    set_time_limit(0);

  • , 'CURLOPT_TIMEOUT'

    curl_setopt($ch, CURLOPT_TIMEOUT, 20);//20

  • . , script .

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);

+1

Source: https://habr.com/ru/post/1598598/


All Articles