Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8369415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:38:19+00:00 2026-06-09T13:38:19+00:00

Which is faster in PHP: echo file_get_contents(‘http://example.com/file.txt’); or $file = file_get_contents(‘http://example.com/file.txt’); echo $file; I

  • 0

Which is faster in PHP:

echo file_get_contents('http://example.com/file.txt');

or

$file = file_get_contents('http://example.com/file.txt'); echo $file;

I am using server side includes (require('/var/www/menu.php');) for my menus etc but want to use this for certain things (eg on other domains)

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:38:21+00:00Added an answer on June 9, 2026 at 1:38 pm

    If you use this method hugely on everypage for very large files, then you would waste memory space by extra variables. so the better approach would be:

    echo file_get_contents('http://example.com/file.txt');
    

    It would be a better question to ask which function is faster file_get_contents() or fread()? Then the answer was if file is more than 1MB or 2MB then use file_get_contents() which can perform better.
    You can see a benchmark here:

    File Read Type          Average Execution Time            Type of File 
    file_get_contents()        0.3730ms                          Small 
    fread()                    0.1108ms                          Small 
    file_get_contents()        0.012ms                           Large 
    fread()                    0.019ms                           Large 
    

    Large file was 2.3MB and the small one was about 3.0KB.
    I ran both functions against small files 100,000 times and ran it again on large file just once.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know which approach is faster, using the pure PHP in
Which statement should I use in php scripts? Echo or Print? What is faster
I am using PHP and SimpleXML and was wondering which will be faster and
I know that using single quotes around a string in PHP is faster than
I'm building a wepage in php using MySQL as my database. Which way is
To find the number of elements in a PHP $array , which is faster/better/stronger?
Which do you think is faster in a PHP script: $query = SELECT... FROM
i wonder which installation to use for my php? i will be using apache.
Which is faster: Union or Concat ? I don't care about the order of
Possible Duplicate: Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.