0

I've hosted an app on Heroku that uses the PHP code to send cURL request for google cloud messaging service using answer in this stackoverflow post

GCM with PHP (Google Cloud Messaging)

However the following code gives me an 500 error in Heroku while it works perfectly well on my shared host, I'm new to Heroku so is there any specific thing I have to do to overcome the error?

<?php
    // Replace with the real server API key from Google APIs
    $apiKey = "your api key";

    // Replace with the real client registration IDs
    $registrationIDs = array( "reg id1","reg id2");

    // Message to be sent
    $message = "hi Shailesh";

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

    $fields = array(
        'registration_ids' => $registrationIDs,
        'data' => array( "message" => $message ),
    );
    $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_POSTFIELDS, json_encode( $fields));

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // curl_setopt($ch, CURLOPT_POST, true);
    // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode( $fields));

    // Execute post
    $result = curl_exec($ch);

    // Close connection
    curl_close($ch);
    echo $result;
    //print_r($result);
    //var_dump($result);
?>

Thanks

rksh
  • 3,920
  • 10
  • 49
  • 68
  • Can you provide server error log? Maybe curl extension is not installed ? – Radek Adamiec Feb 01 '16 at 18:36
  • That's what I thought but their documentation says that things like cURL is pre installed https://devcenter.heroku.com/articles/php-support – rksh Feb 01 '16 at 18:39
  • It seems like server fault. So without error log It will be very difficult to resolve this – Radek Adamiec Feb 01 '16 at 18:40
  • As a wild guess, could it be to do with SSL certificates being different, as you are calling a `https` URL? – Magnus Smith Feb 10 '16 at 22:09
  • Did you solve this problem? I try to call a webservice using nusoap, it uses cURL, and is throwed the follow error: HTTP Error: cURL ERROR: 27: SSL: couldn't create a context: error:140A90C4:SSL routines:SSL_CTX_new:null ssl method passed url: https://_xxxxx_:443/_xxxxx_.Services content_type: http_code: 0 header_size: 0 request_size: 0 filetime: -1 ssl_verify_result: 1 redirect_count: 0 total_time: 0.241638 namelookup_time: 0.004367 – Natan Bueno Jul 11 '17 at 18:46
  • In other server its running ok. – Natan Bueno Jul 11 '17 at 18:46

0 Answers0