fsockopen and curl

Discussion in 'PHP' started by daboss, May 11, 2007.

  1. #1
    what's the difference? i need to access a file or a web page on one web server from another web server. which one would you go for? what's the pros and cons of each?
     
    daboss, May 11, 2007 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Go for Curl, it supports gzip compression by default. All professional file fetching solutions use Curl as it's much faster and more flexible (for complex situations, such as form enetring etc.)
     
    T0PS3O, May 11, 2007 IP
  3. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #3
    does curl come default with php? any custom installation required?

    also, what about fsockopen... any problems?
     
    daboss, May 11, 2007 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not by default but any professional hosting solution will have included. Do a phpinfo and look for curl to be sure.

    Fsockopen through file_get_contents if pretty convenient for grabbing an entire page. No issues but if the page doesn't respond it will slow down your script whereas with Curl you can set a timeout.
     
    T0PS3O, May 11, 2007 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    curl needs to be installed on the system when you compile php for it to be included as an extension, however most systems have it installed, to test do

    
    <?php 
    if(!function_exists( "curl_init") )
      echo "No curl";
    else
     echo "Curl installed";
    ?>
    
    PHP:
    If you have curl then use it, as mentioned it's way faster than any other methods, like fsockopen and actual sockets.

    Also posting can be a pain in the ass with sockets ...... and useragents, and cookies
     
    krakjoe, May 11, 2007 IP