help with curl

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chimanrao
Forum Newbie
Posts: 2
Joined: Tue Sep 09, 2008 1:08 am

help with curl

Post by chimanrao »

here is the snippet below, i keep getting curl error number 7, couldn't connect to host.
I tried using the IP address instead of the URL.

Code: Select all

 
        $url = "http://www.google.com";
 
        $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
                                                curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_HEADER, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        $data = curl_exec($ch);
 
        //Error Checking
        echo "<pre>";
        print_r(curl_getinfo($ch));
        echo "\n\nErrorNum: " . curl_errno($ch);
        echo "\n\nError: " . curl_error($ch);
        echo "</pre>";
        
        curl_close($ch);
        echo $data;
 
 
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: help with curl

Post by andyhoneycutt »

I have no problem executing this code on my test box. Works fine. Can the machine that you are using to execute this code ping http://www.google.com?

-Andy
chimanrao
Forum Newbie
Posts: 2
Joined: Tue Sep 09, 2008 1:08 am

Re: help with curl

Post by chimanrao »

I am not sure how to execute this, its a hosted website, I have only ftp access to it.
The host is http://www.3shost.com
When I logged the service request, the arrogant technical specialist said my code might be wrong..

is there any other way I can test this?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: help with curl

Post by andyhoneycutt »

Sorry for the late reply! I've been away. cURL isn't a part of the default installation of the php5 package, with default options, so your host may not have it available. They may also be denying use of cURL out of some security guideline they have. You may try using fopen() or some other less robust function/object to handle what you're trying to do.

-Andy
Post Reply