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 Fragment及Activity 中使用sharedpreferences

Android Fragme...

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

判斷字串是否存在於內容中

判斷字串是否存在於內容中

searchphoto5 以下範例~ 搜尋 If you are lucky enough to b...

php定時執行任務ignore_user_abort() 函式

php定時執行任務ignor...

ignoreuserabort() 函式 PHP , PHP 5, PHP 最近剛好有一個專案需要定...

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