Jump to content

Recommended Posts

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.

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/

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.