Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-06-2007, 08:15 PM
aryam aryam is offline
Newbie
 
Join Date: Nov 2006
Posts: 1
Rep Power: 0
aryam is on a distinguished road
Default Which should I use?

Which should I use, require or include? Why? And whats the difference?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-07-2007, 12:46 AM
v0id's Avatar   
v0id v0id is online now
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,626
Last Blog:
CherryPy(thon)
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

The functions works almost identical, but there's one difference. They both return a warning message is something is wrong, like the file don't exists, or similar. But require returns a fatal error, which means that the script don't continue, if something is wrong. include would continue.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-07-2007, 01:45 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Aside from the minor difference v0id pointed out there is a major difference in performance.

I've been reading a lot on optimizing my PHP code performance. In fact when I get time, maybe this weekend, I would like to do some in depth benchmarking on many PHP functions. When I was beginning PHP I found that there were many functions that do the same exact thing (neglecting minor differences) [include-require, str_replace-preg_replace, print-echo, ect...]. Your question was always in the back of my head. Which one is better? I never could figure out the answer, so I just randomly picked one.

However, with my resent research, I've realized that there are major differences regarding optimization. Just the other day I read an article from Zend and it stated that include() is seven times slower than require()

After that, I went back in my code and changed all my include()'s to require()'s because it even makes more sense in my case.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-07-2007, 02:44 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Quote:
Originally Posted by Sidewinder View Post
Aside from the minor difference v0id pointed out there is a major difference in performance.

I've been reading a lot on optimizing my PHP code performance. In fact when I get time, maybe this weekend, I would like to do some in depth benchmarking on many PHP functions. When I was beginning PHP I found that there were many functions that do the same exact thing (neglecting minor differences) [include-require, str_replace-preg_replace, print-echo, ect...]. Your question was always in the back of my head. Which one is better? I never could figure out the answer, so I just randomly picked one.

However, with my resent research, I've realized that there are major differences regarding optimization. Just the other day I read an article from Zend and it stated that include() is seven times slower than require()

After that, I went back in my code and changed all my include()'s to require()'s because it even makes more sense in my case.
That is interesting to know. What books are you reading for this information?
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-07-2007, 03:19 PM
v0id's Avatar   
v0id v0id is online now
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,626
Last Blog:
CherryPy(thon)
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

I agree, it's pretty interesting. Can you provide a link, or some other material where you got the information from?

I just picked this up from PHP.net:
Quote:
Originally Posted by http://php.net/require
require() and include() are identical in every way except how they handle failure.
To me it seems like they're working in the same way, but throws different errors? Maybe the fatal error, thrown by require, is faster, because it don't have to give the user detailed information about what just occurred, it will just halt. But it still seems unlikely that this could cause the big difference in performance.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 09-07-2007, 03:23 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Perhaps once it is Zend encoded there is a difference? Zend may be changing the response times of PHP functions somehow. It is hard to understand how once could be 7 times faster unless we are talking 1/7 Nano Seconds.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-07-2007, 05:37 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Quote:
Originally Posted by Jordan View Post
Perhaps once it is Zend encoded there is a difference? Zend may be changing the response times of PHP functions somehow. It is hard to understand how once could be 7 times faster unless we are talking 1/7 Nano Seconds.
The actual purpose of encoding in Zend is to make the code faster, hence the extension name "Zend Optimizer," but thats not what I was talking about. Just the performance difference between include and require while not encoded. Of course I'm not talking in a matter of seconds [actually depends on the file size], but with normal files < 50kb you wont notice a difference perse, but the difference is close to milliseconds.

Ill write an article on this because there is A LOT of tweeks people overlook such as:

PHP Code:
//requires path normalization
include "file.php"
is slower than
PHP Code:
//avoid path normalization
include "/home/user/file.php"
Ill see if I can get xdebug setup and post the statistics
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall

Last edited by John; 09-07-2007 at 05:40 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 09-07-2007, 08:51 PM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,149
Rep Power: 18
Lop will become famous soon enoughLop will become famous soon enough
Default

Nice tips! I'd love to see/learn more, where did you learn them from?
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 05:40 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads