I made a script where there's a simple forum and tutorial posting feature. And I am planning on making a large site. So how would I implement a caching system. How does caching work. What are good tutorials out there for caching?
There are several client-side and server-side caching options. The best choice depends on your type of site and server. Here is a substantial article from Sitepoint: Cache it! Solve PHP Performance Problems
How large of a site do you plan on making? Unless it is handling thousands of requests per second, you probably won't need to cache.
Not true, sites on shared servers can give you grief after 1000's / day ... not second. function make_content_file($filename,$content,$opentype) { $fp_file = fopen($filename, $opentype); fputs($fp_file, $content); fclose($fp_file); } PHP: Use that to cache your output to a folder, then just check if a file exists BEFORE running any php on your page. If the page exists, just display the cache and bypass the php. If you can't figure this post out, there are tons of tuts out there. Just google it
A cache system I have implemented I found to be pretty easy to create. Basically, the idea is to capture the content and store it in a flat file for retrieval each time around. I decided to make a key for each item using md5 and stored it in an XML file. Before I call any content, I check if the cache file exists, if so I load that, use SimpleXML to grab the content and print it. Otherwise, I query the database and load info from there. I took it a bit further by making everything sort of a half flat file, half database driven site. When I create an article in the admin, it sends the info to the database but also creates the cached page. Upon editing an item, I allow the option to choose to update the cached copy. There is also an option not to flush the cache, to use it as a flat file. The cache is never flushed, and if it doesn't exist, it's created once the page is viewed. Send me a PM if you want the script.
I think maybe more people would like a script like that - if possible, could you post it here, or on pastebin or something similar? Good resources should be shared
Okay, I have inserted quite a bit of commenting to help those who find it useful get a grasp on using it. I am making a CMS that uses this, and it works very well. Short, simple and to the point. Some parts you may want to check error handling. I have an error logger, and had to remove those parts quickly so it didn't get confusing, which I think I replaced with return null or false. Read the comments, and if you find you need a live example let me know, I will make something really quick.