2

I have created a simple cms to build simple websites for my customers. The cms is database-driven. I would like to make a offline/cache/static copy of the websites, to increase performance.

Is there any php script available, that traverses a website and creates a static version?

3
  • Why PHP? Won't wget or httrack do? Commented May 16, 2012 at 8:39
  • I would like to automate it, so the user can start the process by pressing "Publish" within the cms. That is why I was hoping for PHP (the cms is developed with PHP). Commented May 16, 2012 at 9:40
  • @Eydun my solution would allow this approach Commented May 16, 2012 at 10:03

3 Answers 3

1

You can do many things to optimize the sites, most do not traverse the site and create a cache, you could write your own class which is quite simple or you could use one already written:

http://www.jongales.com/blog/2009/02/18/simple-file-based-php-cache-class/

The way it would work is the first time someone visits the live page create a cache if the cache does not exist if however the cache does exist serve up the cache version

Sign up to request clarification or add additional context in comments.

1 Comment

If you are going to be using full page caching it would make sense to use ob_start();, ob_get_contents(); and ob_end_clean(); php.net/manual/en/function.ob-start.php
1

Make one yourself and integrate it into your simple CMS?

There is a lot of possibilities which you can use like Memcache, APC and just plain static files generated by your application.

Your question is pretty vague since you haven't provided any real problems with writing your cache. But besides the two first options I mentioned, a simple static file cache can be accomplished with file_get_contents, file_put_contents and filemtime

Example (loose):

<?php


if( file_exists("/cache_dir/".$page_name) && (time() - filemtime("/cache_dir/".$page_name)) > 300)
{
  $contents = file_get_contens("/cache_dir/".$page_name);
}
else
{
  // getting the page contents
  ob_start();

  //output your page

  $contents = ob_get_clean();
  file_put_contens($contents, "/cache_dir/".$page_name);
}

echo $contents;

?>

It's a short and loosely created example but it might help you get an idea how to make a solution that fits your application.

Comments

0

Caching, especially when it's offline, is done by most modern browsers automatically. Since PHP is a server-side language, it's restricted to only effect stuff on the "online" end. If you want to increase performance though, you can try automatically minifying your resources via PHP.

If you're super-intent on storing data offline, you could see what you can fit into cookies, but I don't really see that as a conventional method.

EDIT:

If you mean making static pages on the server side, then yes. With the right permissions, you can create and edit pages with fopen() and related functions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.