Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 55715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:25:15+00:00 2026-05-10T17:25:15+00:00

Everything I read about better PHP coding practices keeps saying don’t use require_once because

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:25:15+00:00Added an answer on May 10, 2026 at 5:25 pm

    require_once and include_once both require that the system keeps a log of what’s already been included/required. Every *_once call 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:

    if (!defined('MyIncludeName')) {     require('MyIncludeName');     define('MyIncludeName', 1); } 

    I’ll personally stick with the *_once statements but on silly million-pass benchmark, you can see a difference between the two:

                    php                  hhvm if defined      0.18587779998779     0.046600103378296 require_once    1.2219581604004      3.2908599376678 

    10-100× slower with require_once and it’s curious that require_once is seemingly slower in hhvm. Again, this is only relevant to your code if you’re running *_once thousands of times.


    <?php // test.php  $LIMIT = 1000000;  $start = microtime(true);  for ($i=0; $i<$LIMIT; $i++)     if (!defined('include.php')) {         require('include.php');         define('include.php', 1);     }  $mid = microtime(true);  for ($i=0; $i<$LIMIT; $i++)     require_once('include.php');  $end = microtime(true);  printf('if defined\t%s\nrequire_once\t%s\n', $mid-$start, $end-$mid); 

    <?php // include.php  // do nothing. 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use a UNION to combine the queries. Wrap them in… May 11, 2026 at 6:20 pm
  • Editorial Team
    Editorial Team added an answer 1: up to you; you can't really do anything about… May 11, 2026 at 6:20 pm
  • Editorial Team
    Editorial Team added an answer Increase your memory until you have enough and make sure… May 11, 2026 at 6:20 pm

Related Questions

Everything I read about better PHP coding practices keeps saying don't use require_once because
Silverlight v2.0 is getting closer and closer to RTM but I have yet to
A common task in programs I've been working on lately is modifying a text
I'm writing my first app with ASP.NET MVP (attempting Supervisory Controller) and Unit Testing
I was just reading about Linq to SQL being discontinued. For a while I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.