Solved

Slow Loading php Page

Posted on 2007-03-26
5
232 Views
Last Modified: 2013-12-13
I have a php page that seems to take about 12 seconds to load. The entire page file follows:

<?php
      session_start();
      $apwd = $_REQUEST['apwd'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
      <title>Scheduling - Check Admin Pwd</title>
<?php
// Logic to check password against database goes here
$Host = "db663.perfora.net";
$User = "dbo200869341";
$Password = "HK4cGqAu";
$DBName = "db200869341";
$TableName = "parameters";

$Link = mysql_connect ($Host, $User, $Password);

$Query = "SELECT * from parameters";
$result = mysql_db_query ($DBName, $Query, $Link);
$row = mysql_fetch_row ($result);      
$badpwd = 1;
if ($adpwd == $row[1]) {
      $badpwd = 0;
      $_SESSION['pwd'] = $adpwd;
      $_SESSION['alast_used'] = time();
}      
      
?>                        
<style type="text/css">
      .pt10 {font-size: 10pt; font-family: Arial}
      .pt8  {font-size: 8pt; font-family: Arial}
      .pt9  {font-size: 9pt; font-family: Arial}      
      .pt7  {font-size: 7pt; font-family: Arial}
</style>            
<script language="JavaScript">
<!--
      badpwd=0;
<?php
      print("msel = $msel;\n");
      if ($badpwd == 1) {
            print ("badpwd = $badpwd;\n");
      }      
?>      
function go_action() {
      if (badpwd == 1) {
            window.location = "admin_menu.php?bad=1";
      } else {
            if (msel == 1) {
                  window.location = "admin_admin.php";
            }
            if (msel == 2) {
                  window.location = "rpt_sel.php";
            }            
            if (msel == 3) {
                  window.location = "custs_all.php";
            }                  
            if (msel == 4) {
                  window.location = "un_pwdt.php";
            }                  
            if (msel == 5) {
                  window.location = "inst_custs.php";
            }                                          
      }
      return true;
}      
// -->
</script>                  
</head>

<body onLoad="return go_action();">
      <b><font color="red"><blink>Please wait while database information is retrieved.....</blink></font></b>
</body>
</html>

The reason for the message after the body tag is to keep people from going away until the next page loads.

I have an almost identical page on the SAME WEB SERVER that takes about 2 seconds to finish. The ONLY difference is a different database.

Why does this take so long
0
Comment
Question by:Richard Korts
  • 3
5 Comments
 
LVL 24

Accepted Solution

by:
glcummins earned 500 total points
ID: 18795595
The most obvious reason I see for this problem is this line:

$Host = "db663.perfora.net";

First, this is on a remote server (I assume), so the speed of your script is dependent on the response time of that server.

Second, and most importantly, you are using a name rather than an IP address. This means that the name must first be converted to an IP via a DNS lookup, which always adds some time. Rather than 'db663.pefora.net', try using the IP address of the server.
0
 
LVL 14

Expert Comment

by:Aamir Saeed
ID: 18795605
is this ok?

if ($adpwd == $row[1]) {
      $badpwd = 0;
      $_SESSION['pwd'] = $adpwd;
      $_SESSION['alast_used'] = time();
}      

i think you want to use $badpwd instead off $adpwd
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18795618
Another minor change you can make to gain a little speed, change:

$Query = "SELECT * from parameters";

to

$Query = "SELECT * from parameters LIMIT 1";

It appears that your script is only using one line of the result, so tell the MySQL server that you only want one line. This speeds up the response, especially if the 'parameters' table is large. MySQL knows it can return the result immediately after the first record is found, rather than looking at every record.
0
 

Author Comment

by:Richard Korts
ID: 18795723
Reply to all:

Thanks for your quick responses.

(1) The code that refers to "db663.preforia.net", that is EXACTLY the same code (except that the address is different) for the other version of this that works fast. But I'll try to get the IP address. All the other pages in this app use that same coding and NONE of the others are slow.

(2) I'll try SQL "Limit 1". It's true there is ONLY one record in that table.
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18796071
A note from the PHP manual regarding the use of mysql_db_query():

   This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead.

Depending on your version of PHP, this may also gain you a little performance edge.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now