1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

which is faster, File_get_contents or cURL?

Discussion in 'PHP' started by karjen, May 25, 2016.

  1. #1
    so I am creating an auto import script and I know that cURL is more flexible but my question is, is it faster than file_get_contents? and which one is using more memory?
     
    karjen, May 25, 2016 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Write a simple script that makes a function call 1000 times and have one version that does file_get_contents and one version that does curl. Do you memory test at the beginning and end and test the difference. If it's just speed then you can use time() to check that.

    your thread title says faster, your post talks about memory so I'm not sure which one (both?) matters to you.

    
    function fgctest(){
    //all the file gets contents stuff
    }
    function curltest(){
    // all the curl stuff
    }
    
    $fgcTime = time();
    for($i=0; $i < 1000; $i++){
       fgctest();
    }
    echo "<p>fgc time: ". time() - fgcTime;
    
    $curlTime = time();
    for($i=0; $i < 1000; $i++){
       curltest();
    }
    echo "<p>curl time: ". time() - curlTime;
    Code (markup):
     
    Last edited: May 25, 2016
    sarahk, May 25, 2016 IP
  3. karjen

    karjen Active Member

    Messages:
    54
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    73
    #3
    Thanks.. Ill be looking through this..
     
    karjen, May 26, 2016 IP
  4. sma2007

    sma2007 Member

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #4
    File_get_contents not designed for remote operation, it is suitable only for a local reception of the content, although it and do a lot of work analogues of CURL.
     
    sma2007, Jun 7, 2016 IP