performance - How can I speed up my PHP based website? -
i built small php based site scratch, yay me! given size of it, it's running little slower expected.
i have files/folders organized 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 of php files coded 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 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; // url of page we're looking @ $('#article-nav-pg a').each(function() { if (loc.indexof(this.href) !== -1) { // if url contains href of anchor $(this).addclass('selected'); // mark 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 have html codes directly inside. appreciate advice on how improve speed on small php based site.
thanks
first of need measure:
- how slow "slow"?
- is slow consistent?
- does site become very slow when many users visit it?
then find bottlenecks, design changes, implement changes , measure again. @ point ought specify how want improve things , after stop.
most of times bottleneck database. database queries optimization subject whole book, if use mysql have @ slow query log. quantify site's performance characteristics have @ jmeter.
edit: found out (from source) not using mysql. need measure , provide numbers. how page render time start with?
on unrelated note though, careful direct file inclusion security issue you've got there.
Comments
Post a Comment