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

  • SEARCH
  • Home
  • 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 7903123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:40:02+00:00 2026-06-03T09:40:02+00:00

I would like to ask about the performance and memory usage of instantiating an

  • 0

I would like to ask about the performance and memory usage of instantiating an object in php.

On every php file of my application, i included a file which connect to the database.

$db->DB::getInstance();
$db->connect('all my credentials');

This is the getInstance() function in my db class.

//singleton database instance
public static function getInstance() {
    if (!self::$Instance) {
        self::$Instance = new DB();
    }

    return self::$Instance;
}

Currently everything turns out well. But i am concern of performance issues as in, can it be improved, possbile flaws etc.

I researched and found out that singleton instance can help to save memory. It will reuse the object if it’s already been instantiate. Am i right?

My exact question is

E.g. if i have 10 users accessing the script, does it means that the object will be instantiate 10 times? When that happens, will it put 10 x load on my memory usage? -> this is pretty what i am interested in

Appreciate any expert advice.

  • 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. Editorial Team
    Editorial Team
    2026-06-03T09:40:04+00:00Added an answer on June 3, 2026 at 9:40 am

    As with all performance tweaking, you should measure what you’re doing instead of just blindly performing some voodoo rituals that you don’t fully understand. When you save an object in $_SESSION, PHP will capture the objects state and generate a file from it (serialization). Upon the next request, PHP will then create a new object and re-populate it with this state. This process is much more expensive than just creating the object, since PHP will have to make disk I/O and then parse the serialized data. This has to happen both on read and write.

    In general, PHP is designed as a shared-nothing architecture. This has its pros and its cons, but trying to somehow sidestep it, is usually not a very good idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would like to ask about how do I write a preg_replace in PHP to
I would like to ask about memory management with regards to MKReverseGeocoder , prior
I would like to ask about the effect of writing to global memory in
I would like to ask about the available (free or not) Static and Dynamic
I would like to ask you about regular expressions preg_match have outlined below. I
I would like to ask you about some advices about this code. It works,
i would like to ask a question about @UsesJAXBContext annotation in jax-ws. I try
I have been reading about unsafePerformIO lately, and I would like to ask you
I would like to ask such question, I have XML xsd`s, which generate beans
I would like to ask about some advices, how to use Symfony2 SonataAdminBundle. I

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.