Blogs

Check and clear cache in CodeIgniter with this Output extension

I decided to write an extension to the CodeIgniter core Output library as it's great for working with cache but doesn't contain any mechanisms for clearing or managing the cache.

Installation

Download the extension (details below) and extract the MY_Output.php file to your application/core folder. The core output library is loaded automatically so the extension should load automatically too. If you have changed the extension prefix to something other than MY_ in your config.php file you will need to update the extension file appropriately.

Clearing a cached path

You can clear any specified path of its cache by calling $this->output->clear_path_cache('path/to/clear');. This method will return boolean TRUE if successful, FALSE if not.

if ($this->output->clear_path_cache('path/to/clear'))
{
    //Cache has been cleared for 'path/to/clear'
}
else
{
    //Cache not cleared - check file exists / permissions
}

Clearing all cache

You can clear the entire cache directory by calling $this->output->clear_all_cache();.

Note: this will not remove the .htaccess and index.html files in the applications/cache folder.

$this->output->clear_all_cache(); //This method returns NULL

Checking to see if a path is cached

You can check to see if a specified path has been cached by calling $this->output->path_cached('path/to/check'), which will return BOOLEAN TRUE if cache does exist for the path or FALSE if it doesn't.

if ($this->output->path_cached('path/to/check')
{
    //The path 'path/to/check' is cached
}
else
{
    //There is no cache doe 'path/to/check'
}

Checking the expiration time of a cached path

You can check to see when a specified path's cache will expire by calling $this->output->get_path_cache_expiration('path/to/check/). This will return the an INTEGER of the timestamp when the cache is due to expire or BOOLEAN FALSE if there is no cache for the path.

$cache_expires = $this->output->get_path_cache_expiration('path/to/check/');
 
if ($cache_expires > 0)
{
    //The cache for 'path/to/check' will expire on the unix timestanp $cache_expires
}
else
{
    //There is no cache for 'path/to/check'
}

Download

The project is hosted on github, so you can always download the latest version from there.

License

I added the GNU Public License (GPLv3) to this extension. Read http://opensource.org/licenses/gpl-license.php for more information.

Comments, questions and suggestions

I hope you find this extension useful. If you have any comments please leave them in the comments section below. Thanks!

Book review: OpenCart 1.4 Template Design Cookbook by Tahsin Hasan

OpenCart 1.4 Template Design Cookbook thumbnailOpenCart isn’t a system I’ve used before but Packt Publishing asked me to review OpenCart 1.4 Template Design Cookbook by Tahsin Hasan for them so I thought it’d be a good opportunity to learn more about an ecommerce shopping cart system. I spend a lot of time working on PHP/MySQL applications, including Drupal and CodeIgniter, but I haven’t used OpenCart before, so I’m coming to this book and application completely new.

OpenCart is a complete ecommerce shopping cart solution, with features including multi-currency support, product ratings and reviews, downloadable products and a discount coupon system, and it is of course customisable and templatable. OpenCart 1.4 Template Design Cookbook promises to help you get to grips with the basics of template design, as well as styling search results and customising the design of the administration panel to match either yours or your clients’ brand.

'Close Account' options for web applications

Exit It's very rare that I come across a web app which allows me to close my account. Granted, it's not a feature you want to encourage people to use but if people want to stop using your app then they'll probably just abandon the account anyway. From a user's perspective I like to feel in control so being able to close an account, even if I don't chose to do so, can be quite reassuring. However, I think there are also some advantages for developers and stakeholders to benefit from by implementing a 'close account' feature.

First of all, you probably don't want to lose users - you want them to keep using your app and tell all of their friends. But sometimes things don't always work out this way, and although you may be getting lots of people sign up to your app, are they coming back to use it weeks or months down the line? Knowing how many new accounts doesn't really help unless you also know how many are leaving. Adding a 'close account' feature will give you an insight into how long people decide to keep using your app before they walk (and they'll probably do that whether you allow them to close their account or not).

You might also be able to get some feedback by adding a small form or comment box asking why they are leaving. If they are leaving because something isn't working as expected, they will probably tell you and you'll have a chance to put it right. By doing this it may also be possible to convince people to stay by making the process interactive, learning why they want to leave, and hopefully giving them the information they need to change their minds.

Finally, going back to my first point from a user's perspective - people like to feel in control. They may have created an account and misspelled a username or just don't require it anymore, and in an age where so much of our information is online, it reassures people that they can remain in control of their data.

I'd love to hear what your experiences are with building account closure features into your web apps and why you have or haven't chosen to do so. I don't think every app or site should (or shouldn't) have this feature, but these are just some possible advantages from a developer and user perspective. Please feel free to leave comments using the link below.

Blog from the iPhone to your Drupal blog with BlogPress

There are a couple of apps which can post to Drupal as well as the majority of other popular blogging platforms straight from your iPhone: iBlogger and BlogPress. I'm writing this from BlogPress on my iPhone, but the app also supports the iPad for all you lucky folks out there. With BlogPress you can view previous posts, save drafts, upload images to Flickr or Picasa and upload movies to YouTube, all of which can then be embedded straight into the post. Drafts can be saved to the app and are stored on the iPhone or can be stored on your Drupal site. No more excuses for not having enough time to blog!

If you know of any other apps for blogging from the iPhone, especially to Drupal, please add them in the comments below. Happy remote blogging :)

Upcoming book review: OpenCart 1.4 Template Design Cookbook by Tahsin Hasan

Tags:

OpenCart 1.5 Template Design Cookbook front coverPackt Publishing kindly asked me to write another review for an upcoming book: OpenCart 1.4 Template Design Cookbook. The book covers a range of techniques for customising the header, footer, store navigation, creating dynamic content, custom error pages and sitemaps. The author, Tahsin Hasan, is a fellow CodeIgniter developer and has worked with other PHP frameworks such as Zend, Symfony and CakePHP.

I’ll be posting the review in the next few weeks. In the meantime, here is a link to a sample chapter: Chapter 3 - Layout Structure.

Other links

Create amazing explorable panoramas on the iPhone with Photosynth

I've just been playing with Photosynth for the iPhone. It allows you to take multiple pictures from different angles then stitch them together to make a 3D, explorable panoramic. So what's so different about Photosynth? Well, you can also create 'Synths' which are 3D spaces made up of images from not only different angles but different locations. This means you can take a picture of a building from different sides and Photosynth will work its magic and make it into a 3D model which you can explore.

Optimising Drupal performance

There are a few great out of the box performance tweaks which Drupal offers to speed up page loading times and minimise server load. First of all, these tweaks wouldn't suit every site. You need to first think about how much traffic you currently get and how often our content changes. You don't necessarily have to add or amend a page for content to change; people can post comments and interact with your site in ways which change the content displayed. This will make a difference to how you chose to optimise your Drupal site performance.

Fighting blog comment spam

I've noticed a recent influx of blog spam which seem, to some degree, relevant to the content it's posted on. I think spammers are composing comments targeted to specific subject areas and then searching the web for content on that subject so that when they post the comment it appears at first glance to be genuine. Of course the most telling part is the totally unrelated link to men's watches or postal degrees which seem somewhat out of place in a comment on a php web development framework. Nevertheless, if you're not careful the comments can slip through the net and appear on your blog. The other issue which has become more of a problem lately is the spammer's ability to evade CAPTCHA challenges. I've increased the level of noise and distortion for the CAPTCHA challenge on this blog but some still get through. It's as if there is a person actually typing in a response to the challenge, in which it won't be of much help. There are a few ways in which you can help fight, reduce and manage blog spam, because let's face it - it's not going to stop entirely. So let's have a look at some quick first pointers.

New 'Mix Radio' on Last.fm

Since Spotify I've slightly neglected my Last.fm radio favouring playlisted music over radio style chosen tracks, but I may start using the Last.fm radio again since they've introduced the new 'Mix Radio' station. It's a great way to discover new music without being overwhelmed by too many unfamiliar tracks.

What is 'Mix Radio'?

Mix Radio combines:

  • New recommendations (similar to the 'Recommendations' station)
  • Tracks by artists in your library that you haven't scrobbled before and
  • Tracks in your library that you already know.

Last.fm is great for listening to music when you don't know what you want to listen to or you want to hear something you haven't heard before but you might like. The new 'Mix Radio' station does the job nicely, and if you hear something you really don't like just skip it or, if Last.fm completely misjudged your taste, ban it and Last.fm will learn what you don't like. Last.fm is great for all music fans so if you haven't used it before I'd definitely recommend giving it a try – it's free and can be accessed from the website, through the free downloadable player, through Android and iPhone mobiles and even through many new DAB/Wi-Fi radios.

For more information on the new 'Mix Radio' station from the official Last.fm blog, visit:
http://blog.last.fm/2010/10/29/mix-radio-a-new-radio-station

Qwiki: Information Experience

The recent TechCrunch disrupt award saw startup Qwiki win disruptive product for their information experience website which seeks to change the way we consume information. This is the kind of thing which we've seen in movies for years but Qwiki is making this experience a reality by pulling together information from various sources and presenting it in a much more experiential way. This sort of delivery is probably well suited to that kind of research where you hear a term you haven't heard before and you want to know more. You'll probably start by typing the term into Google then sift through the (usually first result) Wikipedia page followed by image search and/or movies etc. What Qwiki does is pull all of this together for you so you get an instant overview of all the information in a much more 'lean back' way.

The video below is a demo of the product at TechCrunch Disrupt 2010. If you'd like to sign up for their invite-only alpha test head over to Qwiki.com. They also have a few sample Qwikis live on the site.

Qwiki at TechCrunch Disrupt from Qwiki on Vimeo.

Pages

Subscribe to RSS - blogs