PDA

View Full Version : Optimized PHP?


Jake302
01-21-2008, 01:44 PM
Well, I am very new to coding in PHP, and I have been working on my very first website that will be coded in PHP; however, I have finished the first few pages that are actually written in PHP, and I browsed to them and it took me about 10-15 seconds to display the page.

Now, I know 10-15 seconds isn't horrible, but I know that people can become impatient with slow websites and decide it's not worth their time.

So can someone help me optimize my PHP?

Here is my website.

www.atsquad.com

Only the Videos page is working at the moment.

Here is the code for the videos page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<title>Ray Ray Le Tarde's House of Cards</title>
<link rel="stylesheet" type="text/css"
href="http://atsquad.com/style.css" />
<style type="text/css">
.videolist {
width: 400px;
height: 110px;
border-bottom: 1px;
margin-left: auto;
margin-right: auto;
}
.thumbnail {
height:95px;
width: 130px;
position: relative;
top: 10px;
left: 10px;
float:left;
}
.videotitle {
position: relative;
top: 12px;
left: 20px;
font-weight: bold;
}
.videotitle a {
color: #000000;
text-decoration: none;
}
.videotitle a:hover {
color: #39629f;
text-decoration: none;
}
.videodescription {
position: relative;
left: 20px;
top: 20px;
}
.divider {
position: relative;
top: 11px;
width: 90%;
height: 1px;
background: #cccccc;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div id="spacer">
<div id="shadow"><?php require('http://www.atsquad.com/include/nav.php'); require('http://www.atsquad.com/include/header.php'); ?>
<div class="content">
<div class="leftcolumn">
<h2>Latest Videos</h2>
<div class="navvy">
<ul class="navvylist">
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a></li>
</ul>
</div>
<h2>Latest Pictures</h2>
<div class="navvy">
<ul class="navvylist">
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a> </li>
<li><a href="#">Not
Available</a></li>
</ul>
</div>
<!--ends leftcolumn--></div>
<div class="rightcolumn">
<h3>Latest Videos</h3>
<div class="info"><br />
</div>
<div class="maincontevt">
<p><?php $host="censored";
$username="censored";
$password="censored";
$db_name="censored";
mysql_connect("$host", "$username", "$password")or die("Connection Failed");
mysql_select_db('atsquadc_J');
$sql = "SELECT * from videos order by date limit 20"; $res = mysql_query($sql) or die(__LINE__.":".mysql_error()); while($row = mysql_fetch_assoc($res)) {
echo '<div class="videolist"><div class="thumbnail"><img src="http://www.atsquad.com/videos/thumbnails/';
echo str_pad($row['id'], 4, '0', STR_PAD_LEFT);
echo '.jpg" height="85" width="115"></div><div class="videotitle"><font size="2"><a href="http://www.atsquad.com">';
echo $row['title'];
echo '</a></font></div><div class="videodescription"><font size="1">';
echo $row['description'];
echo '</font></div></div><div class="divider"></div>';
} ?></p>
</div>
<!--ends rightcolumn--></div>
<!--ends content--></div>
<?php require('http://www.atsquad.com/include/footer.php'); ?><!--end shadow-->
</div>
<!--end spacer--></div>
</body>
</html>

So can someone tell me what's making the page so slow, and how I can prevent slow pages in the future.

Vege
01-21-2008, 02:46 PM
I don't see anything that could dramatically add to your browsing speed, or anything you should be worrying about.
Took me 2sec to open the page (alltough im behind 24/2Mb connection)

Jim7283
01-21-2008, 03:17 PM
For me the page load was almost instantaneous, but the trouble was connecting to your server which took about 10-15 seconds. I would recommend talking to your ISP about upgrading your hosting account which may allow for faster connections & less waiting time.