views:

75

answers:

1

I just built a small PHP based site from scratch, yay for me! But given the size of it, it's running a little slower than I expected.

I have the files/folders organized like this:

  • articles [folder]
  • css [folder]
  • html [folder]
  • images [folder]
  • js [folder]
  • photography [folder]
  • resources [folder]
  • articles.php [file]
  • bio.php [file]
  • contact.php [file]
  • content.php [file]
  • favicon.ico
  • footer.php [file]
  • header.php [file]
  • index.php [file]
  • photography.php [file]

And most of my PHP files are coded something like this:

<?php

$thisPage="Writing";

include("header.php");


$page = $_GET['article'];
$file = "articles/".$page.".html";
if(file_exists($file)) {
  include($file);
} else {
  print "404 Error. Page does not exist";
}

function IsSafeInclude($x) {
    if(strpos($x, "/../") !== false || strpos($x, "../") === 0 || strpos($x, "/..") == (strlen($x) - 3) || $x == '..')
        return false;
    else
        return true;
}

//include("html/articles-left.html");

?>

<div id="article-nav-container">

        <ul id="article-nav-pg">
            <li><a href="articles.php?article=article_name1">1</a></li>
            <li><a href="articles.php?article=article_name2">2</a></li>
            <li><a href="articles.php?article=article_name3">3</a></li>
            <li><a href="articles.php?article=article_name4">4</a></li>
            <li><a href="articles.php?article=article_name5">5</a></li>
            <li><a href="articles.php?article=article_name6">6</a></li>
        </ul>

        <script type="text/javascript">
                $(document).ready(function() {
            var loc = window.location.href; // The URL of the page we're looking at
            $('#article-nav-pg a').each(function() {
                if (loc.indexOf(this.href) !== -1) { // If the URL contains the href of the anchor
                        $(this).addClass('selected'); // Mark it as selected
                }
            });
        });
        </script>



    </div><!-- end articles nav -->


    <p id="left-description"><img src="images/side-descrip-stories.jpg" width="20" height="90" alt="Story Description" /></p>

<?php

include("footer.php");

?>

Some files also have html codes directly inside. I would appreciate any advice on how to improve the speed on my small PHP based site.

Thanks

+1  A: 

First of all you need to measure:

  • how slow is "slow"?
  • is slow consistent?
  • does the site become very very slow when many users visit it?

Then find bottlenecks, design changes, implement changes and measure again. At some point you ought to specify how much do you want to improve things and after that stop.

Most of the times the bottleneck is the database. Database queries optimization is a subject for a whole book, but if you use MySQL have a look at the slow query log. To quantify the site's performance characteristics have a look at JMeter.

Edit: I just found out (from your source) that you are not using MySQL. So you need to measure and provide us with some numbers. How much is the page render time to start with?

On a completely unrelated note though, be careful for the direct file inclusion security issue you've got there.

cherouvim
The overall site seems to load at 5 secs. All the pages take between 2-3 secs to load, except for the "writing" page, which takes 1 sec or less.The homepage is loading slower than expected at 2.5. It's only composed of a background image and nav links within the content area. Im confused. Along with that the "bio" and "contact" are also delayed, but they are simple layouts.The "photography" page takes the longest at 3.7. It uses a js plugin for a photo gallery.Would gzip and js compressions help? I would like to get pages to load at an avg of 1.5 or less. Thanks for all your help.
gdinari
These render times are completely crazy (long) for what you've shown us in the source code. Something must be really messed up.
cherouvim