?
Solved

Slow Loading php Page

Posted on 2007-03-26
5
Medium Priority
?
269 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 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