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

要如何修改Plesk空間上傳檔案大小的限制

要如何修改Plesk空間上傳...

Plesk的預設狀況下上傳檔案限制為M。 若要修改上傳限制 首先點選開發工具的PHP設定 innim...

將Google字型fonts.googleapis.com新增到CSP header 中

將Google字型fonts...

Content Security Policy (CSP) 內容安全政策 主要用來限制網頁中對外部的...

使用.htaccess關閉特定文件的緩存

使用.htaccess關閉特...

以特定檔案為例 <Files page.php> FileETag None Header unse...

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