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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:15:39+00:00 2026-05-29T08:15:39+00:00

A page on my web site is taking too long to load – about

  • 0

A page on my web site is taking too long to load – about 2 seconds. After using microtime throughout the code I have worked out where it is taking too long and request help on how to speed it up.

The code I use for finding times is

echo "<BR>3 - ".(microtime(true)-$startTime);  #How long it takes for this page to do
$sqldb=open_database();  #Open the database
echo "<BR>4 - ".(microtime(true)-$startTime);  #How long it takes for this page to do

and my results are

3 - 5.1140758991241
4 - 6.1172299385071

So from this I deduce that the function to open the database is taking 1 second.
The function used to open the database is

//This function is to open the database
function open_database() {
    //Now we will connect to the database
    $sqldb=mysql_connect($_SESSION['hostname'], $_SESSION['dbusername'], $_SESSION['password']) OR die ('Unable to connect to database! Please try again later.');
    mysql_select_db($_SESSION['dbname'], $sqldb);  #Select which database we wish to use - in this case the customer one

    if(empty($sqldb)) {  //If there is no database then we have an error - MASSIVE ERROR!
        header('Location:'.$_SESSION['web_site'].'/error.php');
        die();
    }
    return($sqldb);
}

Note that SESSION varibles are used in the mysql_connect so I only have to change one variable when I update to the production server. Hostname is ‘locaLhost’ on the pre-production server.

So my question is – Why is opening the database taking so long? Please note that because I am in pre-production stage the database is very small.

  • 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-05-29T08:15:39+00:00Added an answer on May 29, 2026 at 8:15 am

    Sessions are stored in the file system and reading from the file system also takes time. If they were stored in the php code then they would be immediately available to the script. That’s probably part of your problem.

    Let me offer a possible solution. Create 2 new files.

    dbconfig.prod.php
    dbconfig.dev.php

    Put your database configuration information into each of these files for the correct environment. On the dev server symbolically link dbconfig.dev.php to dbconfig.php on the production server symbolically link dbconfig.prod.php to dbconfig.php Then in your version control ignore dbconfig.php

    Now you don’t have to do something non standard like sessions for database config storage, and it may solve your timing problem. Though IMO 1 second is not a while lot of extra time.

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

Sidebar

Related Questions

One of the web pages on our site is extremely long. Although the page
I'm working on a 10 page web site with a database back-end. There are
I have a page on my web site that reports on the health of
On my web site I have XMLs with my page contents (automatically generated from
On my web site I want to serve user a page with a lot
On my web site, there is an index page, but if I take out
Say I have a web site with a master page and an aspx page.
I have a web site in asp.net that uses a master page. In this
In a VS2008 web site project, I have a page open in split view.
I have a web page in which people go to register for my site.

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.