Everything I read about better PHP coding practices keeps saying don’t use require_once because of speed.
Why is this?
What is the proper/better way to do the same thing as require_once? If it matters, I’m using PHP 5.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
require_onceandinclude_onceboth require that the system keeps a log of what’s already been included/required. Every*_oncecall means checking that log. So there’s definitely some extra work being done there but enough to detriment the speed of the whole app?… I really doubt it… Not unless you’re on really old hardware or doing it a lot.
If you are doing thousands of
*_once, you could do the work yourself in a lighter fashion. For simple apps, just making sure you’ve only included it once should suffice but if you’re still getting redefine errors, you could something like this:I’ll personally stick with the
*_oncestatements but on silly million-pass benchmark, you can see a difference between the two:10-100× slower with
require_onceand it’s curious thatrequire_onceis seemingly slower inhhvm. Again, this is only relevant to your code if you’re running*_oncethousands of times.