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
Old 06-13-2005, 02:26 PM Include vs Require
lajkonik86's Avatar
Ultra Talker

Posts: 389
Trades: 0
Fail to understand what the difference is.
When should i use which?
__________________
Know what to Download

Please login or register to view this content. Registration is FREE
lajkonik86 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-13-2005, 02:35 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
essentially, there is no difference. With "include", if the file being included is not found proccessing continues without error. If you use "require" and the file is not found, your PHP script will get a 'fatal error' and all proccessing will stop.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 07-17-2008, 08:15 PM Re: Include vs Require
Junior Talker

Posts: 2
Trades: 0
I have found that are some other differences in include() vs require()

include() = more resource hungry with heavy server load and low memory
require() = much much less load on the server

here is an example, include() reads the php and evaluates it, require just dumps that bit of code into your page that required it and evals all at the same time.

Imagine you have 5 include on a page, php looks like it does the following...
include1() ... reads ... evals
include2() ... reads ... evals
include3() ... reads ... evals
include4() ... reads ... evals
include5() ... reads ... evals

whereas require dumps all 5 into the main php file and then evals all the code in one go. Imagine you have a few hundred users all simultaneously loading php pages with these includes, you wouldn't really notice except if you try to then load a larger flat file database or something else that may hit your memory with a heavy load at the same time. with the include() you will see it will take a lot lot longer to load the flat file, switch them to requires and your load time will drop dramatically.

I am still trying to think of an instance where you would want to use include over require... I havent yet.

just some observations...
chadsmith76 is offline
Reply With Quote
View Public Profile
 
Old 07-17-2008, 08:40 PM Re: Include vs Require
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Quote:
Originally Posted by chadsmith76 View Post
I have found that are some other differences in include() vs require()

include() = more resource hungry with heavy server load and low memory
require() = much much less load on the server

here is an example, include() reads the php and evaluates it, require just dumps that bit of code into your page that required it and evals all at the same time.

Imagine you have 5 include on a page, php looks like it does the following...
include1() ... reads ... evals
include2() ... reads ... evals
include3() ... reads ... evals
include4() ... reads ... evals
include5() ... reads ... evals

whereas require dumps all 5 into the main php file and then evals all the code in one go. Imagine you have a few hundred users all simultaneously loading php pages with these includes, you wouldn't really notice except if you try to then load a larger flat file database or something else that may hit your memory with a heavy load at the same time. with the include() you will see it will take a lot lot longer to load the flat file, switch them to requires and your load time will drop dramatically.

I am still trying to think of an instance where you would want to use include over require... I havent yet.

just some observations...
Where did you find this information? I don't believe this is the case at all and I belive both actions do the exact same thing.

The only difference that I know they have have is that include will only throw a warning on failure and require will cause a fatel error on failure and actually will cause the PHP parse engine to stop and the script dies.

I use require on my core script files and include with files that won't break the script flow.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Include vs Require
 

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.38904 seconds with 12 queries