Generate static content for performance

Running a very popular and high-bandwidth website or blog? The load is killing the server? The website content is generated in real-time using PHP, .NET or CGI scripts?

You can easily increase your website performance by generating static files and serving such files much faster rather than generating files in real-time. Static files can be kept on the hard drive or in memory for blazing fast access, for example, using memcached.

Generating PHP static content
You can generate PHP output in multiple ways – from PHP code directly writing output to files or by fetching specific PHP output via HTTP protocol, or using PERL code. If you are using specific web server based values and features – you will have to fetch file via HTTP and write output to local file. This is very easy to do and doesn’t require much programming skill.

Fetching file via HTTP using WGET

wget -O /var/www/page1.html

Where /var/www/page1.html is the output file.

Fetching file using CURL

curl -o /var/www/page1.html

fetch -o /var/www/page1.html

lynx -source > /var/www/page1.html

Generating php output using a PHP script:

$files = file(“filelist.txt”);
for($i = 0; $i < count($files); $i++) {
$page = ob_get_contents();
if(strpos($files[$i], “.php”) > -1) {
$file = fopen(substr($files[$i], -4) . “.html”);
fputs($file, $page);

where filelist.txt is the list of the files with every file listed in new line you want it to be generated.

Perl code for fetching a remote website page. Please save the following code into the filename


use LWP::Simple;
getprint ““;
$content = get( $url );
print $content;

And then run it with the following Linux command line:

perl > outputfile.html

In the next article we will review a solution where website content is saved to memcached and content served from fast memory-based cache without generating content on the fly.


  1. aa says:

    any word on the memcached post?:)

Leave a Reply