Solved

Slow Loading php Page

Posted on 2007-03-26
5
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 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