John Knowles - Development Blog

PHP update blues

Post by: John Knowles On 2008-08-19 14:08:02

Recently I have been unable to keep my blog up to date with most of my time being committed to work and a healthy social life. I have recently made a few minor updates to the website to fix an issue which was caused by either a MySQL or PHP update.
The update resulted in the order of my blog being reversed putting the oldest posts at the top. After looking into the problem I found that the problem was partly down to me using the wrong type of quotes within an SQL query 'date' rather than `date`.

Over the past few months I have been spending my days at work developing websites and the e-commerce system I have developed for clients. The process has taught me alot about Object Oriented Programming, PHP, MySQL and server management.

One of the major issues I came accross is a bug within PHP and its mysqli class. The bug stops connections from being cleaned up and causes the MySQL server to reach its maximum connections limit. The result of this is every database managed website on the server returns a fatal error. This bug is going to be fixed within PHP5.3 but until then a tempory fix is to decrease the timeout on each connection and decrease the maximum number of connections per user. The only downside is that this technique causes a slight delay when the maximum number of connections for a user has been reached whilst a connection is cleared for another to be allowed.

I have started using my spare time to build modules for a framework I developed (and use to develop) the most recent being a cashe system which allows a page of section of a page to be cashed for an amount of time. Wether this amount of time is 10 seconds or 10 months the aim is to increase loading speed for the user. This reduces the amount of querys to the database and the amount of processing required for each page if dynamic elements are involved.

An effective example of this would be for a blog or news page. The header and footer will remain consistant unless other parts of the site require frequent updating so these could be cashed for a month. The content of the page however would be updates on a daily/weekly/monthly basis. This wouldn't be a problem and could be cashed seperatly with a shorted expiry. You could however have the cashe expiry set to an almost infinate number and have the system remove the cashe file each time the news is updated within the admin.

With the increase in number of users on the internet and the amount of dynamic/interactive content increasing every resource counts. Using techniques such as this can reduce the requirement for expanding your hardware setup and save your users precious time.