Web Development

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.

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.

Book review: CodeIgniter 1.7 by Jose Argudo Blanco and David Upton (Packt Publishing)

The CodeIgniter framework is a secret weapon for many web developers as it allows you to quickly build complex web applications in a structured and organised way. I started using CodeIgniter over a year ago now so I've approached Packt's CodeIgniter 1.7 by Jose Argudo Blanco and David Upson as a way of expanding upon when I've already learnt from the user guide, forums and a book which I had previously read from Wrox called Professional CodeIgniter by Thomas Myer.

'PHP Nature' missing from 'Project Natures' in Aptana Studio 2.0

For some reason, even though I have the PHP Development Tools (PDT) installed in Aptana Studio (2.0), I'm not able to select 'PHP nature' in the 'Project natures' of an imported project. I can start a new PHP Project which will have the 'PHP nature' selected as primary nature, but this doesn't even appear as an option in imported projects. The only two natures that are available are 'Remote Nature' and 'Web Nature'. The 'PHP nature' adds some really useful functions, like grouping my @todos into Aptana's Tasks view and also other handy things like auto-completing PHP docblocks.

To get the 'PHP nature' associated with your imported project you can manually edit the .project file which Aptana creates in your imported project directory so that it contains the 'PHP nature'. To do this, add the following code between the <natures> tags in your .project file:

<natures>
   <nature>org.eclipse.php.core.PHPNature</nature>     
</natures>

You may need to re-load Aptana to refresh the project but you should now find that your imported project has a primary 'PHP nature' set.

Note: Please do this at your own risk; although it worked fine for me I don't know if it will cause any side effects to the project or Aptana.

CodeIgniter 1.7 by Jose Argudo Blanco and David Upton

CodeIgniter 1.7I was recently sent a copy of a book from Packt Publishing to read and review called CodeIgniter 1.7 by Jose Argudo Blanco and David Upton. I'll be interested to see how the book compares to what I've learnt so far about CodeIgniter (>1 years experience CodeIgniter and >4 years php) and see what else it can offer, especially in terms of planning and managing application projects. The description on the Packt Publishing website says:

"This book explains how to work with CodeIgniter in a clear logical way. It is not a detailed guide to the syntax of CodeIgniter, but makes an ideal complement to the existing online CodeIgniter user guide, helping you grasp the bigger picture and bringing together many ideas to get your application development started as smoothly as possible.

This book will start you from the basics, installing CodeIgniter, understanding its structure and the MVC pattern. You will also learn how to use some of the most important CodeIgniter libraries and helpers, upload it to a shared server, and take care of the most common problems. If you are new to CodeIgniter, this book will guide you from bottom to top. If you are an experienced developer or already know about CodeIgniter, here you will find ideas and code examples to compare to your own."

I'll be posting a review of the book on my blog shortly. This review is now online.

Links

Firefox or Chrome

Chrome VS FirefoxHere's an edgy stand-off I find myself in the middle of every so often – Google Chrome or Mozilla Firefox as my default browser. From a day to day, quick browse, everything is on the web perspective I'd have to say I prefer Google Chrome. It's fast(er), simple and gets the job done. However, from a web developer perspective Firefox has the add-ons that you so sorely need. I've tried designing a Drupal Zen sub-theme with Chrome's 'inspect element' feature but it's not as comprehensive as the Firebug add-on for Firefox which I couldn't work without. However, when I want to check my daily barrage of social sites Chrome shaves off valuable seconds. For today, I'll leave Firefox as my default browser simply because of the add-ons – they're useful, I need them and I don't mind sacrificing a bit of speed.

Twitter and the short URL conundrum

Although the spam seems to be dying down a little on Twitter since they introduced their 'report as spam' option I'm still a little cautious about clicking some shortened URLs - SO many of the links seem to lead to spam (spam and more spam). The whole concept seems to have gone full circle as well with people using extensions like Long URL Please to make the short URL long again. Although I think this is a good a useful add-on, the whole process seems a little excessive.

Free subversion repository hosting accounts

I've come across a few subversion hosting services which offer free accounts so I thought I'd share the links. Most of these seem to offer a limited free account and a range of paid accounts. If you're working with subversion a lot and you come to rely on them then you may want to upgrade in the future - at least you can try them out first for free. However, if you're developing one or two projects on your own you may be happy to stick with the free account.

Pages

Subscribe to RSS - Web Development