Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 01:17:30 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155554 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: WebsiteBaker with mod_rewrite and PEAR::Cache_Lite  (Read 5615 times)
janit
Guest
« on: March 14, 2005, 09:53:38 AM »

I've played around with website baker for around two weeks now. Generally I really like it, especially the admin interface is nice and clean. Naturally there are a few things that could (in my opinion) use improvement:

 - No support for caching (pages always generated on the fly)
 - I don't like the pages being files (with just id reference and some includes)

These are not critical things, but just something I'm missing. Here are examples of how I modified WebsiteBaker to support caching and get rid of the pages/ -structure.

First off, I used mod_rewrite to parse the requests coming from the clients. This is easy to set up if you've got mod_rewrite installed. Just add the following lines to your .htaccess in the document root (you can also place them to apache conf files):

Code:

RewriteEngine On
RewriteBase /

RewriteCond     %{REQUEST_URI}  !/templates

RewriteRule .+ php/display.php [L]


This will tell apache to send all incoming requests to php/display.php. Exceptions (for images, styles, etc.) can be set using RewriteCond. To check whether mod_rewrite is working ok, just echo "hello world" in your display.php. If it works, then let's move on.

The wb pages-table contains a field called link. This field can be used to dig out the id of the page according to the request. The link is without suffix, so we first need to get rid of it in our display.php:

Code:

$request = explode(".",$_SERVER[REQUEST_URI]);
$request = $request[0];


Once we have it in correct format, we can get the page_id from the database by comparing the request and the link field:

Code:

// require config and database class
require("../config.php");
require(WB_PATH.'/framework/class.database.php');

// setup database object
$database = new database(DB_URL);

// get page id from db
$query = "SELECT page_id FROM pages WHERE link='$request' LIMIT 1";
$page_id = $database->get_one($query);

// move on
require(WB_PATH."/index.php");


So now you have it. Basically the files in the pages -directory are not needed any more. You can still keep them, no problem. It could still use improvements like sending a 404 if there's no matching link for request, etc.

The reason I wanted everything to be parsed through display.php was that then I could easily set up caching using PEAR::Cache_Lite. Cache_Lite simply saves a copy of the data sent to the browser as a file. The copy can be set to be valid for a certain time (say an hour). Any requests coming in within the time limit get the saved copy instead of getting documents generated from the database. Cache_Lite has good documentation online, so I'll just copy the display.php that I used to enable caching:

Code:

$request = explode(".",$_SERVER[REQUEST_URI]);
$request = $request[0];

// include cache class and set her up
require_once('Cache/Lite/Output.php');

$options = array(
// set save dir (must be writable by webserver)
'cacheDir' => '/path/to/cache/files/',
// set cache life time (in seconds)
'lifeTime' => 3600
);

$cache = new Cache_Lite_Output($options);

// if page (identified by $request) does not exist in cache....
if (!($cache->start($request))) {

// require config and database class
require("../config.php");
require(WB_PATH.'/framework/class.database.php');

// setup database object
$database = new database(DB_URL);

// get page id from db
$query = "SELECT page_id FROM pages WHERE link='$request' LIMIT 1";
$page_id = $database->get_one($query);

// move on
require(WB_PATH."/index.php");

$cache->end();
}


The only problem left is the fact that updates via the admin interface don't empty the cache. The following method is crude, but works. I modified class.admin.php:

Code:

function print_footer() {

// cache hack, janit
include(WB_PATH."/framework/cache_clean.php");


This bit includes the cache_clean.php on every page of the admin interface:

Code:

if (strpos($_SERVER[REQUEST_URI],'/pages/')){

require_once "Cache/Lite.php";
$options = array('cacheDir' => '/path/to/cache/files/');
$cache = new Cache_Lite($options);
$cache->clean();

}


Now the cache is being cleaned constantly while you're moving around in the pages-section of the admin interface. That's it. Now you're running a cached WebsiteBaker that's bypassing the pages-directory.

Finally some benchmarks from Siege. I ran a single url for 60 seconds with no cache and then with 20 second cache:

Code:


NO CACHE

Lifting the server siege...done.
Transactions:                    610 hits
Availability:                 100.00 %
Elapsed time:                  60.19 secs
Data transferred:            7271200 bytes
Response time:                  0.96 secs
Transaction rate:              10.13 trans/sec
Throughput:                120804.12 bytes/sec
Concurrency:                    9.76
Successful transactions:         610
Failed transactions:               0
Longest transaction:           14.20
Shortest transaction:           0.07

-------------------------------------------------

20 SECOND CACHE

Lifting the server siege...|done.
Transactions:                   1624 hits
Availability:                 100.00 %
Elapsed time:                  60.14 secs
Data transferred:           19358080 bytes
Response time:                  0.03 secs
Transaction rate:              27.00 trans/sec
Throughput:                321883.61 bytes/sec
Concurrency:                    0.79
Successful transactions:        1624
Failed transactions:               0
Longest transaction:            1.00
Shortest transaction:           0.01


I hope this is of use for somebody Smiley
Logged
Ryan

Offline Offline

Posts: 2048



WWW
« Reply #1 on: March 14, 2005, 10:37:30 AM »

Um, wow. What can I say? I am blown away! After looking at those stats, wow! That is very, very impressive. Caching is definetely something to look at for the future now! I would like to thank you very much for this information! Cool
Logged

Website Baker Project Founder
www.websitebaker.or g

To contact me via email, visit:
www.ryandjurovich.c om
janit
Guest
« Reply #2 on: March 14, 2005, 05:15:59 PM »

Quote from: Ryan
Um, wow. What can I say? I am blown away! After looking at those stats, wow! That is very, very impressive. Caching is definetely something to look at for the future now! I would like to thank you very much for this information! Cool


No problem. Caching takes down the server load on high traffic sites and improves response times for most (when page comes from cache) users. The benchmark in the post does not describe the real world that well... except  for a slashdotted site. Especially if you'd serve the images from another server because otherwise your network would probably choke anyway Smiley
Logged
Steven Holder
The Template Master

Offline Offline

Posts: 493



WWW
« Reply #3 on: March 14, 2005, 09:07:46 PM »

Good work Janit, Im very impressed and hope to see more wonderful work.. =) (Taking a que from Ryans general response =P)
Logged
janit
Guest
« Reply #4 on: March 15, 2005, 06:43:46 AM »

Just realised that it'd be smarter to clean the cache in the admin interface whenever a post has been found (simply if($_POST){clear cache..}).

I'll still have to look into chances for having dynamic content in the cached files... Using Cache_Lite_Output seems to limit this though huh
Logged
bowenmark

Offline Offline

Posts: 62


WWW
« Reply #5 on: March 24, 2005, 08:33:42 AM »

I'm really liking WebsiteBaker so far, was looking for something with an easier admin interface than other cms but wanted caching. Almost there, (have a page with an image/table on it, everything seems to be working splendidly until trying out janit's method), except for this error, (it's not really in the class.mysqldb.php right?) that I don't know where to actually fix: line92 - Gets the first column of the first row

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\Apache2\home\mgweb\public_html\framework\class.mysqldb.php on line 92

Warning: Cannot modify header information - headers already sent by (output started at C:\Apache2\home\mgweb\public_html\framework\class.mysqldb.php:92) in C:\Apache2\home\mgweb\public_html\index.php on line 130

any clues appreciated!
Logged

cheers,

     Mark
     
     MG Web Services
     www.mgwebservices.c a
bowenmark

Offline Offline

Posts: 62


WWW
« Reply #6 on: March 24, 2005, 04:49:33 PM »

I did find some header info being sent per the error message in index.php near line130:
header("Location: ".page_link($default_link));

Will play with this when I get home from my day job this afternoon, Smiley  any clues to the resource not matching in the mysql would be much appreciated still, txs!
Logged

cheers,

     Mark
     
     MG Web Services
     www.mgwebservices.c a
Ryan

Offline Offline

Posts: 2048



WWW
« Reply #7 on: April 07, 2005, 05:05:59 AM »

Any updates on new caching techniques? Cool
Logged

Website Baker Project Founder
www.websitebaker.or g

To contact me via email, visit:
www.ryandjurovich.c om
bowenmark

Offline Offline

Posts: 62


WWW
« Reply #8 on: April 07, 2005, 06:14:29 AM »

No time yet, but it's something that I must get working on my servers as fer sure there is going to be a client that wants this in the future. Will keep the forum posted as no one else seems to have impemented this yet in test4.

Pretty sure it will work, when I was first playing with janit's method it was my first day on WB with an older version and I had all sorts of wonderful things going on while seeing what did what.

 Smiley
Logged

cheers,

     Mark
     
     MG Web Services
     www.mgwebservices.c a
quinto

Offline Offline

Posts: 67


WWW
« Reply #9 on: April 04, 2009, 08:02:41 PM »

It's a 4 years old topic but i want to have more informations about this technique.

I think that using a cache in WebsiteBaker is a "Must Have Feature"...

Why ?

Because with a cache enabled CMS you'll have better performance, displaying page faster, using less ressources on server...

If you have a big site with a lot of traffic a cache system on your CMS is a crucial feature...

Who is using a cache with WebsiteBaker ?

Who is interested in this feature ?

I want to see if i'm the only user who think Caching Feature must be the Better Feature to implement in WebsiteBaker ?
Logged
Luckyluke

Offline Offline

Posts: 555



« Reply #10 on: April 04, 2009, 08:07:15 PM »


I want to see if i'm the only user who think Caching Feature must be the Better Feature to implement in WebsiteBaker ?


Hi,

I believe this will be implemented in WB 3.0.

Grtz,
Luc
Logged
quinto

Offline Offline

Posts: 67


WWW
« Reply #11 on: April 04, 2009, 08:21:11 PM »


I want to see if i'm the only user who think Caching Feature must be the Better Feature to implement in WebsiteBaker ?


Hi,

I believe this will be implemented in WB 3.0.

Grtz,
Luc

But WB 3.0 (Real name is EdgeCMS) will be totally different CMS, nothing is said about compatibility of the modules, templates, etc... used in WB 2.x.

I think EdgeCMS will be a very great CMS but why wait when we can implement this feature in WB 2.x Huh

I think in the future WB 2.x will continue to evolve :

WB 2.8, 2.81, 2.85, 2.9, etc...

And when we'll reach the WB 2.99, we just have to add something in the name like WebsiteBaker Reloaded 1.0  afro

Don't you think that the development of WebsiteBaker will stop when Edgecms will be out Huh

I don't think so Smiley

Then, Why don't try to implement caching feature in WB 2.x ?
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #12 on: April 04, 2009, 08:30:21 PM »

Hi Quinto,

there is obviously a misunderstanding:
WB3 and Edge CMS are not the same. Edge CMS ist a complete different CMS (only started by the same author), but WebsiteBaker has nothing to do with Edge CMS.

So if  this feature is implemented in WebsiteBaker will be decided by the Official Bakers.
I think the best way to get this implemented is to open a ticket:

http://project.websitebaker2.org/newticket

rgds

erpe
Logged

Luckyluke

Offline Offline

Posts: 555



« Reply #13 on: April 04, 2009, 08:31:23 PM »

Hi Quinto,

You see this wrong. You can read everything in this link here.

Grtz,
Luc
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!