| Optimizing Your PHP Scripts |
| Article Index |
|---|
| Optimizing Your PHP Scripts |
| Page 2 |
| Page 3 |
| Page 4 |
| Page 5 |
| Page 6 |
| Page 7 |
| Page 8 |
| Page 9 |
| Page 10 |
| Page 11 |
| Page 12 |
This extremely common situation in Web development is exactly when caching can have remarkable effects at reducing the unnecessary waste of server resources. Using caching, the same book-generating script would operate something like the following:
-
Do any initialization, session management, and so on.
-
Determine the book the user requested to viewed.
-
Check to see whether the cache has the required HTML for the request and output the cached HTML if it does.
-
If the cache entry doesn't exist, retrieve the relevant information about the book from the database.
-
Create the HTML document for the book.
-
Cache the output for future use and output.
By using caching in a situation like this, notice that the two most expensive steps of every request (the retrieval of the data from the database and the output generation) have in most cases been removed. Instead, the script will generate the content once and save it for future use, updating it only after the cached copy has expired. The performance that can be gained from this technique can be staggering (sometimes upwards of 88% faster).
In PHP, caching has been made extremely simple thanks to the PEAR Cache library. Through the use of this library, not only can the entire output of a page be cached, but so can individual components such as function calls and database requests. You can even extend the functionality to create your own custom caches. To start, you will need PEAR Cache installed on your system. This can be done one of two ways. The first is to go to the PEAR website () and download the package, or use the pear command:
[user@localhost]# pear install Cache
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
| Users' Comments (0) |
|
No comment posted








