Solved

Slow Loading php Page

Posted on 2007-03-26
5
236 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php refresh button on the browser 2 36
myqsl update statement on phpMyAdmin 8 21
PHP warning 4 30
PHP: Insert Data into MySQL 5 13
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

911 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

22 Experts available now in Live!

Get 1:1 Help Now