Search code examples
phpcurlcrmrightnow-crmoracle-service-cloud

cURL not working on RightNow/Oracle Service Cloud customer portal


I have a small php script that I'm using to test if cURL is installed and functioning. This works in our Oracle Service Cloud sandbox environment (websitename.rightnowdemo.com), it displays the google.com at the top of the page and below, it prints the result of the test function ("cURL is installed on this server"). The same code in our dev (websitename.custhelp.com) environment, however, does not work. It only prints the "cURL is installed" message and that is all. Is there a configuration setting that needs to be set in our new environment? How can I get cURL fully functioning?

code:

<rn:meta title="cURL Example" template="agent.php" clickstream=""/>

<?php
load_curl();
$curlURL = "www.google.com";
$ch = curl_init($curlURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
$result = curl_exec($ch);
echo $result;
curl_close($ch);

?>

<html>
<head></head>
<body>
<?php

// Script to test if the CURL extension is installed on this server

// Define function to test
function _is_curl_installed() {
    if  (in_array  ('curl', get_loaded_extensions())) {
        return true;
    }
    else {
        return false;
    }
}

// Ouput text to user based on test
if (_is_curl_installed()) {
  echo "cURL is <span style=\"color:#4fa361;\">installed</span> on this server";
} else {
  echo "cURL is <span style=\"color:#dc4f49\">not installed</span> on this server";
}


?>
</body>
</html>

Solution

  • What version of OSvC are you using in production (*.custhelp.com)? More than likely, your versions are different between your demo and production environments. It's best to develop on a true test site that is a clone of your production since the rightnowdemo environment is not in sync with your site. Please include your production OSvC version here as you may need to use the older dl() method to load curl into your script.

    Another issue might be that you're trying to implement your load_curl() method in a view file, which is generally a bad idea. You should be doing that from a controller or a model. You might be running into a namespacing issue introduced in CP3, where namespaces are enforced. Check for curl_init at the root namespace instead of your CP namespace(s).

    if (!function_exists("\curl_init"))
    {
        \load_curl();
    }
    

    With all that said, if you are getting a message that curl is installed, then it should be loading curl properly. More than likely, google.com is rejecting the request from the production server using curl for any number of reasons. You can use the following to check for a curl error:

    if($errno = curl_errno($ch)) {
        $error_message = curl_strerror($errno);
        echo "cURL error ({$errno}):\n {$error_message}";
    }