PHP

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: CodeIgniter 1.7 Professional Development by Adam Griffiths (Packt Publishing)

CodeIgniter 1.7 Professional Development by Adam Griffiths is a great introduction to CodeIgniter - and the Model-View-Controller (MVC) design pattern in general - for intermediate and advanced PHP developers. I was asked to write a review of this book by Packt Publishing and this is now my third CodeIgniter specific book which I've studied. I’ve been working with CodeIgniter on several projects for over two years now so I’ve become quite familiar with the framework, but I’m always interested to see how other people approach problems and use the libraries available. There’re always a few hidden gems which are waiting to be discovered!

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

CodeIgniter 1.7.0 Released

It's that wonderful time again! CodeIgniter 1.7.0 has been released, so it's time to upgrade.

http://codeigniter.com/user_guide/installation/upgrade_170.html

Upgrading looks fairly straight forward - here are some notable changes (http://codeigniter.com/user_guide/changelog.html):

Sessions

Drupal 5.6 and register_globals

Tags:

As of Drupal 5.6 you will no longer be able to install the CMS onto a server with register_globals enabled. The notice on the Drupal website says:

"We no longer support servers with the PHP directive register_globals set to on. Attempts to install Drupal 5.6 when register_globals is enabled will fail. Current installations will continue to function, but will display an error on administration pages and the status report."

This check was introduced as a fix for the Cross site scripting vulnerability (DRUPAL-SA-2008-007) which occurs when register_globals is enabled. I was upgrading my Drupal installation from 5.5 when I found out so I only suffered the error on the status report, but people running a fresh install will find they can’t go any further until they disable register_globals.

Subscribe to RSS - PHP