• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

Slow Loading php Page

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
Richard Korts
Asked:
Richard Korts
  • 3
1 Solution
 
glcumminsCommented:
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
 
Aamir SaeedCommented:
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
 
glcumminsCommented:
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
 
Richard KortsAuthor Commented:
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
 
glcumminsCommented:
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now