Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    132
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question File Get Contents

    I am using php file_get_contents to get an external file to My website....
    But file_get_contents might use more system resources
    I am trying to use CURL instead...

    My php code (that uses file_get_contents) is:
    PHP Code:
    <?php

    $url 
    "http://www.example.com/mail.php";

    $file file_get_contents($url);

    // and replace 'mail' to 'tony' ...
    ?>
    But how can I replace this file_get_contents code to CURL (I want a code that reduce system resources usage and not increasing it...)?

    Any Suggestion Will Be Helpful
    Last edited by Tony M; 05-26-2011 at 03:21 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Something like this(not tested):
    PHP Code:
    $url "http://www.example.com/mail.php";

    $ch curl_init();

    // set URL and other appropriate options
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_HEADER0);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

    // grab URL and pass it to the browser
    $file curl_exec($ch);

    // close cURL resource, and free up system resources
    curl_close($ch);


    $file str_replace('mail''tony'$file);

    file_put_contents('mail2.php'$txt); 
    There are lots of examples in the docs.


  •  

    Posting Permissions

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