php - curl_exec return false while try to connect to URL -


i trying create push notification application send messages server users device.

for registration ids when run curl_exec function following error:

curl failed: couldn't connect host 

i don't know why , made checks , when try change url "google.com" pass. browser if try reach original url redirect me : "https://developers.google.com/cloud-messaging/" php code:

    <?php class gcm {      function __construct() {      }     /**      * sending push notification      */     public function send_notification($registatoin_ids, $message) {         // include config         include_once 'connection.php';          // set post variables         $url = 'https://android.googleapis.com/gcm/send';          $fields = array(             'registration_ids' => $registatoin_ids,             'data' => $message,         );          $headers = array(             'authorization: key=' .google_api_key,             'content-type: application/json'         );         // open connection         $ch = curl_init();          // set url, number of post vars, post data         curl_setopt($ch, curlopt_url, $url);         curl_setopt($ch, curlopt_ipresolve, curl_ipresolve_v4 );         curl_setopt($ch, curlopt_post, true);         curl_setopt($ch, curlopt_httpheader, $headers);         curl_setopt($ch, curlopt_returntransfer, true);          // disabling ssl certificate support temporarly         curl_setopt($ch, curlopt_ssl_verifypeer, false);          curl_setopt($ch, curlopt_postfields, json_encode($fields));          // execute post         $result = curl_exec($ch);         if ($result === false) {             die('curl failed: ' . curl_error($ch));         }          // close connection         curl_close($ch);         echo $result;     } } ?> 

i found server containing firewall blocking outgoing connections. open , working now. solution helped me solve problem link relevant answer.

curl error code 7 (curle_couldnt_connect) explicit ... means failed connect() host or proxy.

the following code work on system:

$ch = curl_init("http://google.com");    // initialize curl handle curl_setopt($ch, curlopt_followlocation, 1); $data = curl_exec($ch); print($data); 

if can not see google page .. url wrong or have firewall or restriction issue

this link me resolve issue


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -