JAGF - Just A General Forum

It is currently Jan 6th, '09, 06:12 • All times are UTC + 1 hour






Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: [PHP]Caching
PostPosted: Nov 16th, '08, 15:51 
Offline
Site Admin

Joined: Jul 29th, '07, 16:35
Posts: 1460
Highscores: 18
How did you find this forum?: I started it :)
PHP caching is easy. Here is how it's done:

Code:
<?php
ob_start(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>x10 Status</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
Some dynamic sitecontent to be cached here please
</body>
</html>
<?php
$buffer = ob_get_contents(); 
ob_end_flush();
$fp = fopen('./cache/content.cache','w'); 
fwrite($fp,$buffer); 
fclose($fp); 
?>


What you need to do here:

Create a folder called "cache", in this folder, create a file called content.cache.

Now create the file to be cached with the code up there ^.

Now create index.php, in this file, write:

Code:
<?php 
if (file_exists('./cache/content.cache')) 

readfile('./cache/content.cache'); 
exit(); 
}
else {
   echo "FAIL";
}
?>


Also, chmod the cache folder to 777.

First, when you visit index.php, it gonna be blank. now run the file that should get cached, containing the first code. Visit index.php again and you will see it work.

Now if you want, run a cron on the file with the dynamic content. This is good for scripts that check the status of a server etc.

Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.

Design by phpBB 3 Skins & Forum Hosting | Modded by ExchangeCore

CSS Template by RamblingSoul | Sponsored By Bargain Finder