Ankur
Ankur

Reputation: 51100

This curl command doesn't work for some reason

I have a URL that I need to "call" from a PHP script. The URL makes a phone call using Tropo's API, so it's easy to verify if it was called.

My PHP looks like this:

<?php

$oid=$_GET["oid"];
$notify_url = "http://mydomain.com/somepath/".$oid;
echo $notify_url;

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $notify_url);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);

mail('[email protected]', 'cURL', "Did a cURL");

?>

This prints out the $notify_url variable, and when I take the printed value and enter it into a browser window, I get the desired result i.e. the phone call to my phone.

I have tried this on two web hosts that claim they support CURL, one is paid (crazydomains.com.ayu - just got off the phone to support) and the other is 000webhost.com

Am I doing something wrong? This one is kind of confusing, since it should be so simple.

EDIT: I receive the mail as expected.

EDIT 2: If you have any ideas about how I can debug this, I would appreciate it.

EDIT 3: As Juhana suggested I added echo curl_error(); after curl_exec and I got this error ...

Warning: Wrong parameter count for curl_error() in /home/a5352876/public_html/curl.php on line 15

EDIT 4: changed the echo curl_error() to echo curl_error($ch) and got the message couldn't connect to host so that seems to be the problem.

Now the question is, why can't it connect to a host that is easily accessible through a browser, is there anywhere I can look for that?

Upvotes: 0

Views: 793

Answers (1)

nickb
nickb

Reputation: 59699

If your host has HTTP wrappers enabled, and the allow_url_fopen config option is enabled, then you don't need cURL, especially for such a simple request.

It looks like all you need to do is open a URL, which you can easily do with fopen():

$oid = $_GET["oid"];
$notify_url = "http://mydomain.com/somepath/".$oid;
$fh = fopen( $notify_url, 'r');
fclose( $fh);

Upvotes: 4

Related Questions