You are seeing » PHP » What is Funky cache?

What is Funky cache?

2011/02/16

Funky cache is a technique to create static files on web server to improve request access speed and was described  in this presentation.

How it works ?

At first, the idea is create static files when the server get a 404 requests, identifing by requested URL.
Your code will try to check if this URL should exists and execute necessary code to build this file.

How fast it is?

I do simple benchmark to demonstrate a comparative speed.
Two files were created test.html and test.php, both empty.
Then, was used the siege tool to do a simple benchmark using following command:
 
siege -t5s -c5 -b local/test.html > /dev/null
 
** SIEGE 2.69
** Preparing 5 concurrent users for battle.
The server is now under siege...
 
Lifting the server siege...      done.
Transactions:                  21364 hits
Availability:                 100.00 %
Elapsed time:                   4.14 secs
Data transferred:               0.53 MB
Response time:                  0.00 secs
Transaction rate:            5160.39 trans/sec
Throughput:                     0.13 MB/sec
Concurrency:                    4.12
Successful transactions:       21365
Failed transactions:               0
Longest transaction:            0.02
Shortest transaction:           0.00
 
siege -t5s -c5 -b local/test.php > /dev/null
 
** SIEGE 2.69
** Preparing 5 concurrent users for battle.
The server is now under siege...
 
Lifting the server siege...      done.
Transactions:                  15971 hits
Availability:                 100.00 %
Elapsed time:                   4.23 secs
Data transferred:               0.30 MB
Response time:                  0.00 secs
Transaction rate:            3775.65 trans/sec
Throughput:                     0.07 MB/sec
Concurrency:                    4.20
Successful transactions:       15971
Failed transactions:               0
Longest transaction:            0.03
Shortest transaction:           0.00

Results:

test.html => 5160.39 trans/sec
test.php  => 3775.65 trans/sec
 
This demonstration show that empty test.php file need be parsed by PHP and results has a lower trans/sec than test.html file.
 
Then I can conclude that to use simple .html files should be delivered to more users requests, but only by the server, you have to consider the size of file, how many files need to load the page like css, javascript and image files and so on.
 
You have to consider that test.php has no code inside, then when you put some of code the trans/sec will decrease.

How to implement ?

You need to configure your server (.htaccess is a good place) to redirect 404 requests to your code.
 
On first request, where it will get a 404 request, your code will be called writing the file from URL request.
 
On next requests, the file will be there returning it.
 
So if you need clean or change the content of .html file, so delete this .html file that it will be generated in a future request.
 
 
I hope that you have understood what is and how works Funky Cache, and if have some doubt, please post a comment.
 
 
Enviroment test: Apache/2.2.16 (Ubuntu), PHP 5.3.3-1ubuntu9.3 with Suhosin-Patch (cli)



Name : Email :