+ Reply to Thread
Results 1 to 10 of 10

Thread: curl time outs

  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Default curl time outs

    Hi I'm trying to use curl to make a request to a remote server, and for what ever reason it keeps timing out. I've tested this code on another server and it works fine. I've tried several sites including, google.com, yahoo.com, bing.com, ebay.com and facebook.com. I'm pretty sure that all those sites wouldnt be down at the same time. Which makes me wonder if there is something wrong with the specific server I am on. Here is the code for argument sakes, its pretty simple and pretty much a copy/paste from the php manual. Also I am on the basic shared hosting plan. I have checked the php config and curl is enabled, and allow_url_fopen is set to On.

    PHP Code:
    <?php
    $ch 
    curl_init("http://www.facebook.com/");

    // set URL and other appropriate options
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_CONNECTTIMEOUT10);
    curl_setopt($chCURLOPT_HEADER0);
    curl_setopt($chCURLOPT_PORT80);

    //echo the results
    echo curl_exec($ch);

    //echo the error message
    echo curl_error($ch);
    // close cURL resource, and free up system resources
    curl_close($ch);

    ?>
    Thanks for your help in advance.

  2. #2

    Default

    If you want to access external servers from your account, you have to purchase a dedicated IP address.
    He is no fool that gives what he cannot keep to gain what he cannot lose. - Jim Elliot
    4ChristMinistry.org - Web development tutorials and Community forum.
    Demos - Kicking the tires on some popular software.

  3. #3
    Join Date
    Aug 2008
    Posts
    17

    Default

    Port 80 is always open regardless of if you have a dedicated IP or not.

    As for your problem, you need to supply a user-agent or Facebook doesn't like it:

    Code:
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");

  4. #4
    Join Date
    Feb 2010
    Posts
    4

    Default

    Treeluvin, I had contacted the hostmonster support department and they confirmed that you need to have a dedicated ip to make external requests. Also it takes a few days for the dedicated ip change to take full effect after purchase, and yes facebook requires a user agent with every request, but a different error code is given. But the others I listed do not and they were also not working. I am not entirely sure why it takes a few days, but my guess is because of the internal structure of hostmonster.

  5. #5
    Join Date
    Oct 2006
    Location
    Laneville, TX
    Posts
    1,225

    Default

    You can use cURL to access remote URLs. Port 80 does not require a dedicated IP.

    The following PHP function works fine for me:

    PHP Code:
    function get_url_contents($url){
            
    $crl curl_init();
            
    $timeout 30;
            
    curl_setopt ($crlCURLOPT_URL,$url);
            
    curl_setopt ($crlCURLOPT_RETURNTRANSFER1);
            
    curl_setopt ($crlCURLOPT_CONNECTTIMEOUT$timeout);
            
    $ret curl_exec($crl);
            
    curl_close($crl);
            return 
    $ret;

    Einstein Computers LLC - Computer services, repair, and web development in East Texas
    _________________________________________________
    myphpscripts.net : scottlecompte.com : objurgate.net : ua-tracker.com

  6. #6
    Join Date
    Feb 2010
    Posts
    4

    Default

    Maybe it was the package we had purchased because I was getting timeouts, and there isnt much different between the code I am using and the code you have posted. Now when I make a request to google.com it returns instantly like it would when you make a normal request using your browser, but before the dedicated ip it was timing out on 10 seconds.

    Also like I said when i contacted the support department, they said I need to have a dedicated ip to make the request.

    Maybe we can have a hostgator employee make a post confirming that you need a dedicated ip or that you infact do not need a dedicated ip. So far there has been 2 moderators that cant agree on what has happening.

  7. #7

    Default

    It is something HM changed in the last 9 months or so. It isn't a total blackout I don't think, but (most) requests originating from the server (hosting account) are now blocked unless you have a dedicated IP address.

    I went at it with HM when I found out. Almost left them over it. I also think, as I mentioned before, that it isn't a complete blackout for outbound traffic, but it might be. I had to stop development on a pretty good component for Joomla! because of the change.

    If I have time this weekend, I will get in touch with Support and ask them to give me a rundown on the new policy for outbound traffic. It might be a combination of what us moderators have been saying.

    ~regards, and sorry for the confusion. We are simple users like yourself.
    He is no fool that gives what he cannot keep to gain what he cannot lose. - Jim Elliot
    4ChristMinistry.org - Web development tutorials and Community forum.
    Demos - Kicking the tires on some popular software.

  8. #8
    Join Date
    Oct 2006
    Location
    Laneville, TX
    Posts
    1,225

    Default

    I wrote a simple php script using the above posted code. I do not have a dedicated IP. View the results at http://www.boogerwelds.com/test/google.php

    The entire contents of the page are as follows:

    PHP Code:
    <?php

    function get_url_contents($url){
            
    $crl curl_init();
            
    $timeout 30;
            
    curl_setopt ($crlCURLOPT_URL,$url);
            
    curl_setopt ($crlCURLOPT_RETURNTRANSFER1);
            
    curl_setopt ($crlCURLOPT_CONNECTTIMEOUT$timeout);
            
    $ret curl_exec($crl);
            
    curl_close($crl);
            return 
    $ret;
    }  

    echo 
    get_url_contents("http://www.google.com");

    ?>
    Last edited by sjlplat; 02-06-2010 at 07:11 PM.
    Einstein Computers LLC - Computer services, repair, and web development in East Texas
    _________________________________________________
    myphpscripts.net : scottlecompte.com : objurgate.net : ua-tracker.com

  9. #9
    Join Date
    Feb 2010
    Posts
    4

    Default

    Ok so I just finished talking to hostmonster support again, and I asked about this issue as well. The person I talked to said that you do not need a dedicated ip to make external requests with curl. So that solves that debate.

    I also asked why I was not able to make curl requests until I received a dedicated ip. They did not know the answer. I also asked why I was told by a support agent that I needed to buy a dedicated ip, they did not know either. The only real answer that I got was sometimes they need to make a modification to a server to enable curl to make these requests. But nothing was stated as fact that pertained to my exact issue.

    I'm guessing that the change that is made to the server is also part of giving an account a dedicated ip. So who knows what really happened or why the servers shadmego and I are on needed the change for this.

  10. #10
    Join Date
    Feb 2008
    Location
    Chicago
    Posts
    84

    Default

    Just FYI, it is not just curl. I have a ruby app that makes scheduled outbound queries (on port 80) and it has been working fine for months.

    I do not have a dedicated IP address.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts