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

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

.htaccess與RewriteEngine一起使用時500內部服務器錯誤

.htaccess與RewriteEngine一起使用時500內部服務器錯誤

在某些情況下,可能未加載apache中的modrewrite模塊。 這時只需要執行以下...

如何將mysql table auto_increment重設

如何將mysql table auto_increment重設

photo 資料表裡的資料加加減減,一不小心突然驚覺當初的欄位長度設定的不夠⊙⊙ 當然...

PHP輸出到WORD跟EXCEL 簡易做法

PHP輸出到WORD跟EXCEL 簡易做法

pexelsphotooffice WORD: $filename="...

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