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

當域名 DNS 尚未生效時,如何預先設定及測試網站

當域名 DNS 尚未生效時,...

建置一個新的網站或是將網站搬家時 常常會遇到一個問題,就是要將網址指向到新的網站空間,設定完畢但需要...

修改apache設定

修改apache設定

pexelsphotolock5 進入apache資料夾,找到conf資料夾(預設是C:\AppSe...

Android Fragment及Activity 中使用sharedpreferences

Android Fragme...

在Android下想要儲存執行資料的方式有好幾種,例如存在手機空間或者是資料庫空間。 這裡紀錄一下使...

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