Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Difference between include() and file_get_contents()
Old 12-03-2007, 12:41 AM Difference between include() and file_get_contents()
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Does anyone know...

Imagining that the file being called is local and it is plain text, is there any difference (particularly with regards to speed) between using

PHP Code:
    ob_start();
    include(
$file);
    
$contents ob_get_contents();
    
ob_end_clean(); 
and

PHP Code:
    $contents file_get_contents($file)? 
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.

Last edited by fambi; 12-03-2007 at 12:49 AM..
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 12-03-2007, 01:28 AM Re: Difference between include() and file_get_contents()
Novice Talker

Posts: 5
Trades: 0
if it's just plain text then file_get_contents will be faster.
NightCrawler is offline
Reply With Quote
View Public Profile
 
Old 12-03-2007, 02:58 AM Re: Difference between include() and file_get_contents()
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Thanks.

Are you sure or is that a guess?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 12-03-2007, 06:47 AM Re: Difference between include() and file_get_contents()
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the get_contents would be marginally quicker.

When a file is included the parser has to do a context switch from "PHP mode" to "HTML Mode" until it either reads a <? delimiter or hits EOF, it then has to switch back to "PHP mode"
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-03-2007, 08:30 AM Re: Difference between include() and file_get_contents()
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Excellent. Thanks for the explanation.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 12-03-2007, 03:40 PM Re: Difference between include() and file_get_contents()
SmartBomb's Avatar
Average Talker

Posts: 27
Name: Dave
Trades: 0
Quote:
Originally Posted by chrishirst View Post
the get_contents would be marginally quicker.

When a file is included the parser has to do a context switch from "PHP mode" to "HTML Mode" until it either reads a <? delimiter or hits EOF, it then has to switch back to "PHP mode"
Nice explaination. Anyway, I've been using require_once() to include bits of php code that's reused on my sites. I take it tht the get_contents() doesn't parse PHP so it would essentially be useless for my application ?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
SmartBomb is offline
Reply With Quote
View Public Profile
 
Old 12-03-2007, 04:28 PM Re: Difference between include() and file_get_contents()
Spiros's Avatar
Experienced Talker

Posts: 40
Name: Spyros
Location: Athens, Hellas
Trades: 0
It cannot be used to include PHP code.

The file_get_contents() function reads a file, and throws the content into a pre-specified string. As of this, yes, it is indeed useless for your case.

- Spyros.
Spiros is offline
Reply With Quote
View Public Profile
 
Old 01-21-2008, 09:40 PM Re: Difference between include() and file_get_contents()
carloncho's Avatar
Skilled Talker

Posts: 80
Name: Carlos
Trades: 0
is not matter of velocity. file_get_contents() returns the content of the file. include() not take the content in a variable, simply include the content and, if there is php code, excecutes. file_get_contents() not excecute nothing.
__________________
-----------------------

Please login or register to view this content. Registration is FREE
carloncho is offline
Reply With Quote
View Public Profile Visit carloncho's homepage!
 
Reply     « Reply to Difference between include() and file_get_contents()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40291 seconds with 12 queries