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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:37:53+00:00 2026-05-13T13:37:53+00:00

My latest idea for do settings across my php project I am building was

  • 0

My latest idea for do settings across my php project I am building was to store all my settings in a config PHP file, the php file will just return an array like this…

<?php
/**
 * @Filename app-config.php
 * @description Array to return to our config class
 */
return array(
    'db_host' => 'localhost',
    'db_name' => 'socialnetwork',
    'db_user' => 'root',
    'db_password' => '',
    'site_path' => 'C:/webserver/htdocs/project/',
    'site_url' => 'http://localhost/project/',
    'image_path' => 'C:/webserver/htdocs/fproject/images/',
    'image_url' => 'http://localhost/project/images/',
    'site_name' => 'test site',
    'admin_id' => 1,
    'UTC_TIME' => gmdate('U', time()),
    'ip' => $_SERVER['REMOTE_ADDR'],
             'testtttt' => array(
                     'testtttt' => false
                     )
);
?>

Please note the actual config array is MUCH MUCH larger, many more items in it…
Then I would have a Config.class.php file that would load my array file and use the magic method __get($key). I can then autoload my config class file and access any site settings like this…

$config->ip;
$config->db_host;
$config->db_name;
$config->db_user;

So I realize this works great and is very flexible, in my class I can have it read in a PHP file with array like I am doing now, read INI file into array, read XML file into array, read JSON file into array. So it is very flexible for future projects but I am more concerned about performance for this particular project that I am working on now, it will be a social network site like facebook/myspace and I have had one before prior to this project and once I got around 100,000 user’s performance became very important. So I am not “micro-optimizing” or “premature optimizing” I am stricly looking to do this the BEST way with performance in mind, it does not need to be flexible as I will only need it on this project.

So with that information, I always read about people trying to eliminate function calls as much as possible saying function calls cause more overhead. SO I am wanting to know from more experienced people what you think about this? I am new to using classes and objects in PHP, so is calling $config->db_user; as costly as calling a function in procedural like this getOption(‘db_user’); ? I am guessing it is the same as every time I would call a setting it is using the __get() method.

So for best performance should I go about this a different way? Like just loading my config array into a bootstrap file and accessing items when I need them like this…

$config['db_host'];
$config['db_username'];
$config['db_password'];
$config['ip'];

Please give me your thoughts on this without me having to do a bunch of benchmark test

  • 1 1 Answer
  • 1 View
  • 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-05-13T13:37:53+00:00Added an answer on May 13, 2026 at 1:37 pm

    From tests I’ve seen, I believe Alix Axel’s response above is correct with respect to the relative speed of the four methods. Using a direct methods is the fastest, and using any sort of magic method usually is slower.

    Also, in terms of optimization. The biggest performance hit for any single request in the system you describe will probably be the parsing of the XML/INI/JSON, rather than the accessing of it via whichever syntax you decide to go with. If you want to fix this, store the loaded data in APC once you parse it. This will come with the one caveat that you will want to only store static data in it, and not dynamic things like the UTC date.

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

Sidebar

Related Questions

I use IDEA 11, updated to its latest version. I opened an Eclipse project
has anyone an idea how to convert a UIImage to cocos2d-x CCSprite. My latest
My latest project is to build a billing system with multiple profile like 100+
I get latest Slik SVN and download my project: svn co https://mycompany.com/svn/product/ I get
when I create a Android project. IDEA has noticed error that this version is
I'm using the latest Drupal 7.2 core and I have no idea how to
guys any idea if this is related to the latest firefox built? or how
I have just downloaded the latest community installer (5.5.27) along with the workbench (5.2.41).
I am currently building an Excel 2007 Add-in using VSTO (latest version + sp1)
I have an idea of monitoring all SQL queries on a spare monitor which

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.