Category Archives: PHP

PHP is a programming language suited to a wide variety of tasks and widely supported by the web development community. Also in this category is PHP’s most common database buddy, MySQL

How to Run Cron Jobs in CodeIgniter

After a fair bit of trawling Google, I got the impression that setting up a cron job in codeigniter was going to be a bit tricky.

The two potential solutions I discovered were:

  1. execute the “wget” command to replicate a normal browser request, which then exposes my cron functionality to the big wide world and creates some additional unnecessary overheads, or
  2. Create a bespoke front controller a bit like the existing index.php but specifically for cron jobs

Neither of these options sound particularly ideal to me, and thankfully, there is a better way (and it turned out to be a case of RTFM).

Firstly, just create a normal controller. I creatively called mine Cron.

Note the call to $this->input->is_cli_request() which ensures that this controller cannot be accessed directly from a url.

Next we setup our cron job as you would any other, except that you provide the path in a special format.

php /path/to/index.php controller_name method_name ["params"]

The first part is either the command “php” or your server path to php.

The second part is the absolute path to your CI front controller, eg. /path/to/index.php.

The third part is the controller name, followed by the method name, followed by optional parameters.

The CI manual gives the example:

php /path/to/index.php cron foo

If that doesn’t work you might need to specify your path to php. I set mine as follows:

/usr/local/bin/php -f /home/clinic/public_html/index.php cron foo

You can even pass parameters in quotes, which have the same effect as parameters in regular url requests!

/usr/local/bin/php -f /home/clinic/public_html/index.php cron foo “beer”

Posted in PHP | Leave a comment

CodeIgniter Getting Started Surprises

I’ve been looking into the CodeIgniter PHP framework (CI)  for a couple of weeks and want to document some of the surprises and caveats I have discovered. Coming from a non-framework background, I was surprised at how similar the CI conventions are to my own pseudo “framework” that I use on my projects – so I guess I must’ve been doing something right so far!

This is what i’ve learnt.

CI is backwards compatible with PHP4

Which, in my opinion is something they should rectify – ie. retire support in the next major release and move forward. From what I have read about CI vs Kohana (a CI fork), it seems that CI is sacrificing pretty autoloading simply because they remain backwards compatible.

Edit: This is actually incorrect, as of version 2.0.2 the minimum required version of PHP is 5.1.6. Thats to Dale for pointing this out in the comments.

The MVC structure is superb, however…

Alot of tutorials i’ve watched lean towards using helper functions within views, such as for forms. From a developer perspective thats fine, however you can imagine a designer having problems with form_open() when he wants to add a simple class or ID. The upside is that they are just helpers – if you don’t like them, don’t use them.

Speaking of functions

I was surprised to discover the folder full of procedural helper functions. This is nice in terms of using functions anywhere inside the application, although it does seem a little out of place in an OOP framework. It would be nice to see these converted into classes.

Default session security is awful

Usually a PHP session’s data is stored server side and only a small cookie is kept client side to track a user session. However in CI, the session data is stored clientRead more

Posted in PHP | 5 Comments

How to duplicate a phpBB3 theme

If you ever want to duplicate an existing phpBB3 theme, you might be sorely frustrated when you can’t seem to get any of your changes to take hold. It is sometimes necessary to go to the ACP, and hit purge the cache, however there is a further trick.

First, duplicate the theme folder you want to start with, and rename to your theme name.

Second, you need to go to the theme folder, and open style.cfg, /imageset/imageset.cfg, /template/template.cfg, /theme/theme.cfg, in a text editor. All of these files contain name = value. Rename all of these to your theme name.

Upload all of these changes, then head to the ACP and go to the “styles” tab. Click install on your theme.  On the left hand menu, go to each of the style components, and select install for each one. Then head back to the main styles page and click “details” for your theme. Select the imageset, template and theme from the dropdown menu.

Now you should be done!

Posted in PHP | 1 Comment