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 8451317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:12:23+00:00 2026-06-10T11:12:23+00:00

Our app currently works like this: class myClass{ private $names = array(); function getNames($ids

  • 0

Our app currently works like this:

class myClass{

    private $names = array();

    function getNames($ids = array()){
         $lookup = array();

         foreach($ids as $id)
             if (!isset($this->names[$id]))
                $lookup[] = $id;

         if(!empty($lookup)){
              $result;//query database for names where id in $lookup
                      // now contains associative array of id => name pairs
              $this->names = array_merge($this->names, $result);
         }

         $result = array();
         foreach($ids as $id)
             $result[$id] = $this->names[$id];

         return $result;
    }
}

Which works fine, except it can still (and often does) result in several queries (400+ in this instance).

So, I am thinking of simply querying the database and populating the $this->names array with every name from the database.

But I am concerned about how many entries in the database I should start worrying about memory when doing this? (database column is varchar(100))

  • 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-10T11:12:25+00:00Added an answer on June 10, 2026 at 11:12 am

    How much memory do you have? And how many concurrent users does your service generally support during peak access times? These are pertinent pieces of information. Without them any answer is useless. Generally, this is a question easily solved by load testing. Then, find the bottlenecks and optimize. Until then, just make it work (within reason).

    But …

    If you really want an idea of what you’re looking at …

    If we assume you aren’t storing multibyte characters, you have 400 names * 100 chars (assume every name maxes your char limit) … you’re looking at ~40Kb of memory. Seems way too insignificant to worry about, doesn’t it?

    Obviously you’ll get other overhead from PHP to hold the datastructure itself. Could you store things more efficiently using a data structure like SplFixedArray instead of a plain array? Probably — but then you’re losing the highly optimized array_* functions that you’d otherwise have to manipulate the list.

    Will the user be using every one of the entries you’re planning to buffer in memory? If you have to have them for your application it doesn’t really matter how big they are, does it? It’s not a good idea to keep lots of information you don’t need in memory “just because.” One thing you definitely don’t want to do is query the database for 4000 records on every page load. At the very least you’d need to put those types of transactions into a memory store like memcached or use APC.

    This question — like most questions in computer science — is simply a constrained maximization problem. It can’t be solved correctly unless you know the variables at your disposal.

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

Sidebar

Related Questions

We have an app that currently installs itself into 'program files\our app', and it
When my app starts I would like to initialize an UIImagePickerController . Since this
We've been working on implementing timezone support for our Web app. This great SO
Our current app runs in a single JVM. We are now splitting up the
In our current WinForms app, we are displaying millions of records in ListView, using
Our app uses a component that requires a license file in the directory with
Our app runs in jvm 32 bit, even when in windows x64. Now, at
Our app servers (weblogic) all use log4j to log to the same file on
Our app uses a string to house character-values used to indicate enum values. for
Our app supports different browser version from IE to Firefox to Chrome. Now, some

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.