2K Posted June 10, 2009 Share Posted June 10, 2009 Alright...simple as hell question... Does require_once or include_once save more bandwidth than include or require? Link to comment https://forums.phpfreaks.com/topic/161604-solved-requireinclude_once/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 10, 2009 Share Posted June 10, 2009 When used as intended with a local file path, they don't use or affect bandwidth at all. When used improperly with a URL, they use twice the bandwidth of the content because your server is both getting that content from where it is at using a http request and then outputting that content to the browser. For the second case, where a URL is being used, using the once_ versions would save on part of the bandwidth being used if you were including the same content more than once on a page. If you are including the content only once anyway, using the once_ versions does not help at all and in fact the once_ versions take slightly longer because php must first check the table of included files before actually reading the content, whereas the non-once_ versions just direct read the content. Link to comment https://forums.phpfreaks.com/topic/161604-solved-requireinclude_once/#findComment-852779 Share on other sites More sharing options...
PFMaBiSmAd Posted June 10, 2009 Share Posted June 10, 2009 Edit to the above: If you are using a URL and you are getting that content from your own server, you are actually using three times the bandwidth of that content. Once when your server outputs it in response to the http request your php script made by requesting it through a URL. Second when it is read in by your php script with the include/require statement in it. Third when you output it to the browser. Link to comment https://forums.phpfreaks.com/topic/161604-solved-requireinclude_once/#findComment-852786 Share on other sites More sharing options...
PFMaBiSmAd Posted June 10, 2009 Share Posted June 10, 2009 Per your PM question - Each request a browser makes for a page is completely separate from every other request it makes for that same page or a different page. Using the _once versions or non-_once versions have no effect between different requests for one page or requests for any other page on your site. Include/require and the _once versions of those are not shared between requests. The file reads might be cached by the operating system for a short time, so requests for pages using the same include file close together would benefit. Again, if you are reading local files using a file system path, there is no affect on your hosting bandwidth. Link to comment https://forums.phpfreaks.com/topic/161604-solved-requireinclude_once/#findComment-852800 Share on other sites More sharing options...
2K Posted June 10, 2009 Author Share Posted June 10, 2009 Thanks...answers my question. Link to comment https://forums.phpfreaks.com/topic/161604-solved-requireinclude_once/#findComment-852804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.