开发者

Caching content, memory vs file system (PHP and Apache)

开发者 https://www.devze.com 2023-03-23 15:15 出处:网络
I am somewhat new to programming and am having a lot of question about data caching. Say, we have a piece of static content. What\'s gonna be faster: save the content into a php\\html file and output

I am somewhat new to programming and am having a lot of question about data caching. Say, we have a piece of static content. What's gonna be faster: save the content into a php\html file and output the page as is, or use a script that will output the content via apc_fetch() (given it was previously saved in memory)? In the first case Apache will always read the page from the file system and it never keeps pages in RAM, doesn' it? Does current APC implementation work well with FastCGI? Thanks in advance!

I am still not getting as to why do benchmarks show a quadruple speed-up whe开发者_如何学JAVAn using APC caching compared to using the file system, while Apache can load static pages so fast.


Rather than cache the entire page statically, I would cache the parts that are dynamic on that page (database calls etc) then either use the file system or memcache to store those cache results.

Writing out static pages will get more difficult to maintain as the site grows, and will be more overhead if your rebuilding pages more frequently.


Static HTML will always be the fastest. Even with opcode caching, PHP will still have to load and run the script, go to the cache, etc. Apache's main purpose, on the other hand, is to serve static content as fast as possible and is optimized to do so.


If your webserver had to fetch every content item from disk then it would be unbelievably slow. All modern Operating systems implement sophisticated disk caching.

save the content into a php\html file and output the page as is, or use a script that will output the content via apc_fetch()

Accessing a static file (i.e. not a PHP file) will be much, much faster, than accessing a PHP file, parsing the PHP, then executing the PHP to call apc_fetch(). As to whether it would be faster to generate an html page from PHP, or use PHP to retrieve the generated results from APC, the answer will depend on how much effort the PHP has to do

I would expect....

<?php
 print "hello world";
?>

Will be faster than

<?php
 print apc_fetch('hello');
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号