簡體   English   中英

如何加快基於PHP的網站的速度?

[英]How can I speed up my PHP based website?

我只是從頭開始構建了一個基於PHP的小型站點,對我來說! 但是考慮到它的大小,它的運行速度比我預期的要慢。

我有這樣組織的文件/文件夾:

  • 文章[文件夾]
  • CSS [文件夾]
  • html [文件夾]
  • 圖片[資料夾]
  • js [文件夾]
  • 攝影[文件夾]
  • 資源[文件夾]
  • article.php [文件]
  • bio.php [文件]
  • contact.php [文件]
  • content.php [文件]
  • favicon.ico
  • footer.php [文件]
  • header.php [文件]
  • index.php [文件]
  • photography.php [文件]

而且我的大多數PHP文件都編碼如下:

<?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");

?>

有些文件也直接在內部包含html代碼。 對於在我的小型PHP網站上如何提高速度的任何建議,我將不勝感激。

謝謝

首先,您需要測量:

  • “慢”有多慢?
  • 緩慢一致嗎?
  • 當許多用戶訪問該網站時,它會變得非常非常慢嗎?

然后找到瓶頸,設計更改,實施更改並再次進行度量。 在某個時候,您應該指定要改進的地方,然后停止。

大多數情況下,瓶頸是數據庫。 數據庫查詢優化是整本書的主題,但是如果您使用MySQL,請查看慢速查詢日志 要量化站點的性能特征,請查看JMeter

編輯 :我剛剛發現(從您的來源)您沒有使用MySQL。 因此,您需要測量並提供一些數字。 開始頁面渲染的時間是多少?

不過,在完全不相關的注釋上,請小心您所遇到的直接文件包含安全性問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM