PHP Serialize

(This post is for computer-literate people.)

Originally, Boggert would load everything (blog posts, blog design, gadgets on the side) from the database and display it dynamically. This worked for a while, but the constant database activity was really killing the site’s speed.

So, I have implemented SQL caching for Boggert. Basically, this feature memorizes what’s in the database so that all the posts,design,etc.. can be loaded locally from the web server.

Of course, a cache isn’t meant to last forever. Boggert is a dynamic web application because it runs on a database, and not on static files. Therefore, every time a comment is posted, a file is uploaded, or a new post is posted, the cache has to be cleared and recreated.

To make the cache for Boggert, I created two cache files for the two main parts of Boggert. I store these in a password-protected directory because they hold sensitive information.

At the beginning of each PHP file, I initialize a variable called $dbcache and use it to store cache information. It starts by loading the database cache from the appropriate cache file. Afterwards, each database query will check the cache for a response before contacting the database.

I use the built-in PHP serialize function for this. Serialize() converts data (integers, arrays, strings) into a string that can be stored. The good thing about this is that file structure and special characters are all kept in their original state.

Unserialize() converts the encoded string back into data that Boggert can use.

Using this method, page loading has improved dramatically. Most of the time, all required information is stored locally. If the database is down, RogerHub will still be available.


1 CommentAdd one

No Name
Fri, 30 Oct 2009 05:12:04 GMT

Good Job

Post a Comment

Tue, 28 May 2024 17:46:22 GMT