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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    61
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Getting file contents (which one takes up less resources)

    So i have a php script that will get the contents of a file that is around 3MB or so, however allot of users will be calling up on this script. Which one of these is best to get contents of a offsite file.

    readfile, fopen, file_get_contents. Any others? i need to use as little system resources as possible, which one uses the least system resources as well as very effective to grab all the contents of a 3-5MB file.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You don't want to use readfile(), unless you also want to output the file contents (to browser or other place).

    fopen() doesn't read anything; fread() does but is much slower than file_get_contents().

    file() can also be used but but manual says file_get_contents() is faster.

  • #3
    New Coder
    Join Date
    Aug 2002
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you prefer, you might check out curl for speed and security. Much better than the standard php file functions.


  •  

    Posting Permissions

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