codingmasterRS Posted July 9, 2010 Share Posted July 9, 2010 Okay so according to http://the-dro.com/web-design/programming/40-tips-for-optimizing-your-php-code/ 7.require_once() is expensive So what should good optimized code use as an alternative, or do instead? Quote Link to comment https://forums.phpfreaks.com/topic/207237-require_once-is-expensive/ Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 By that is means it's more resource heavy; PHP has to check if the file has already been included first. You're never going to experience performance issues based on that though unless you're talking about a system with thousands of simultaneous requests, or thousands of unique included files. Nit picking if you ask me. An optimized solution though would be to design your application in a way that you know at any point whether or not the file will have been included, and so you're able to just use require with the knowledge you won't be including something multiple times. Quote Link to comment https://forums.phpfreaks.com/topic/207237-require_once-is-expensive/#findComment-1083507 Share on other sites More sharing options...
codingmasterRS Posted July 9, 2010 Author Share Posted July 9, 2010 so just use require NOT require_once? Quote Link to comment https://forums.phpfreaks.com/topic/207237-require_once-is-expensive/#findComment-1083512 Share on other sites More sharing options...
Mchl Posted July 9, 2010 Share Posted July 9, 2010 So just do not care. I'll bet there are other areas in your code that could benefit more from optimisation than whatever you can gain from using require_once() instead of require() or the other way round. Same goes for '' vs "" quoting, for() vs while(), ++$i vs $i++ etc. See this article http://www.brandonsavage.net/micro-optimizations-that-dont-matter/ Quote Link to comment https://forums.phpfreaks.com/topic/207237-require_once-is-expensive/#findComment-1083517 Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 I have no insight into your system so I can't say as to how risky that would be. Consider you have a PHP file filled with functions. The file is independent to the main application flow and is only required for certain functionality. At one point you include the file, but then much later in the application you include it again. Since the file has already been included and you're effectively trying to re-declare the functions, you'll get a fatal error. In certain situations though that event may be rare and unnoticed during any testing, and may go on being unnoticed until someone reports it. Times like that are when include/require_once is really useful, but it's really down to your own initiative to decide whether '_once' is required or not; you know your application better than anyone else. Just don't worry so much about using include/require_once for 'expense' reasons. Quote Link to comment https://forums.phpfreaks.com/topic/207237-require_once-is-expensive/#findComment-1083524 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.