Loading...

PHP Caching Headers

Temperature: 0 °C

Mark ChangMark Chang
author_tools


PHP Caching Headers
最近測試平台系統執行速度,老實說測試的有點無力~

總覺得能做的可以做的都做了,但速度就是快不了~

不管是用哪種測速平台測試,都不盡理想。

Google PageSpeed Insights給了我一個方向。

Caching

為什麼要設定Cache?

因為若每次平台開啟都得重新把所有的圖像或框架重新載入一遍那得耗掉多少的網路資源跟時間?

因此,參考了一些Cache的設定,如下:

$seconds_to_cache = 3600;
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: max-age=$seconds_to_cache");

設置快取時間1個小時。

清除快取則是
header("Expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");


先不管測速平台的測試結果如何~至少我的肉眼是有感受到執行速度似乎真的變快了~

總之,先觀察一段時間。

https://innstory.com/story-PHP_Caching_Headers-1708
PHP

Prev
 分享_CNNs_Anthony_Bourdain_dead_at_61

Next
分享_新身分證意外引發統獨之爭 花敬群:大家都想太多了風傳媒 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

Android UI設計距離課題

Android UI設計距離...

layoutmarginTop指定該屬性所在控件距離上方的位置空間。 layoutmarginBot...

mysql 查詢數據資料是否有重複

mysql 查詢數據資料是否...

pexelsphoto5 有沒有試過資料庫裡上萬筆資料卻不知道是不是有重複的數據? 這時你一定要試試...

Ubuntu環境下apache 目錄啟動.htaccess 功能

Ubuntu環境下apach...

.htaccess 檔案是目錄層面的設定檔,可以對目錄變更 Apache 的設定。 要使用 .hta...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format