Following my previous post about installing PHP5.3 on Jaunty, I have had a few requests about installing it on Karmic. I’ve never used Karmic before so I thought it would be a fun excuse to have a poke about whilst also keeping my blog (sort of) up-to-date.
After freshly installing Karmic (the desktop version looks very nice btw) on a new VirtualBox image and then updating with the latest, er, updates I was ready to begin.
The entire installation procedure is very simple, once all dependencies are met.
Firstly you must edit your sources list to include the DotDeb package repository and the old Jaunty security packages to meet dependencies.
$ sudonano/etc/apt/sources.list
# php5.3
deb http://php53.dotdeb.org stable all
deb-src http://php53.dotdeb.org stable all
deb http://security.ubuntu.com/ubuntu jaunty-security main
Now update and upgrade Ubuntu
$ sudoapt-get update
$ sudoapt-get upgrade
You may find that you get the following warning:
WARNING: The following packages cannot be authenticated!
libevent-1.4-2
Install these packages without verification [y/N]?
I just answered Y and continued as normal
Once successfully upgraded then you can install Apache, MySQL and PHP as normal, feel free to cater the installation line to your tastes.
You will get a warning about untrusted packages being installed but this simply means that the PHP5.3 stuff is not signed, so I typed in “yes” and carried on.
After you have installed everything you need to, test it out, either command line:
$ php -v
PHP 5.3.2-0.dotdeb.1 with Suhosin-Patch (cli)(built: Mar 9201010:14:53)
Copyright (c)1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c)1998-2010 Zend Technologies with Suhosin v0.9.29, Copyright (c)2007, by SektionEins GmbH
Or by using phpinfo() page within your Apache installation:
$ sudonano/var/www/info.php
<?PHP
phpinfo();
?>
then fire up http://localhost/info.php and at the top of the page you should see something along the lines of PHP Version 5.3.2-0.dotdeb.1
Note: if your browser asks if you want to download info.php, simply restart Apache and try again:
$ sudo/etc/init.d/apache2 restart
All done. Not quite as simple as on Jaunty, but still better than compiling the source!
Post Script: Before starting this post, I did a quick search looking for tutorials to see if the work had already been done, but couldn’t find anything on installing PHP5.3 on Karmic. As there wasn’t anything I decided to continue with my tutorial and I ended up struggling for an hour or so with the dependency issues. Typically, after I had figured it out for myself, whilst searching for another dependency issue I found this post on the JMOZ blog about installing PH5.3 on Karmic Koala. No idea why it’s not in Google, but either way, damn, I could have saved myself an hour or so!
As you can see, if we set F1 twice, it effectively “unsets” F1 and sets F2. Not what we were after.
So why is this? Well, it’s kind of obvious and I was being a bit of a muppet for not spotting it yesterday. The reason is pretty simple: 1 + 1 = 2. (I told you it was obvious!)
Clearly this is not what we want, but how can we solve this? By using the bitwise OR. If we change the statements slightly as follows:
$f1_or_set= BASE | F1; // $f1_or_set = 1echo"F1 OR set = $f1_or_set\n";
$f1_or_set_twice=$f1_or_set | F1; // $f1_or_set_twice = 1 - huzzah!echo"F1 OR set twice = $f1_or_set_twice\n";
As far as “unsetting” the flags if we use my original method we fall (again) into trouble.
$f1_and_f3= BASE | F1 | F3; // $f1_and_f3 = 5;$unset_f3=$f1_and_f3- F3; // $unset_f3 = 1echo"Unset F3 = $unset_f3\n";
$unset_f1=$f1_and_f3- F1; // $unset_f1 = 4;echo"Unset F1 = $unset_f1\n";
Now, if we try to “unset” F1 twice, we arrive at the problem.
$unset_f1=$f1_and_f3- F1; // $unset_f1 = 3;echo"Unset F1 = $unset_f1\n";
Unsetting F1 twice here effectively turns off F3 and sets F1 and F2 – completely wrong!
Instead, if we use the &~ binary operator mentioned in Jesper’s comment all works as expected. (note: I can’t find mention of this operator in the PHP docs, please someone help me out)
$f1_and_f3= BASE | F1 | F3; // $f1_and_f3 = 5;$unset_f3=$f1_and_f3&~ F3; // $unset_f3 = 1echo"Unset F3 = $unset_f3\n";
$unset_f1=$f1_and_f3&~ F1; // $unset_f1 = 4;echo"Unset F1 = $unset_f1\n";
Even if we try to “unset” a flag twice, it still has the same results:
$unset_f1=$f1_and_f3&~ F1; // $unset_f1 = 4;echo"Unset F1 = $unset_f1\n";
$unset_f1_twice=$unset_f1&~ F1; // $unset_f1_twice = 4;echo"Unset F1 twice = $unset_f1_twice\n";
Also in Jesper’s comment and original post was the use of the left shift operator: <<. After playing around with this it seems very simple to use, as follows:
After all this I think I am a little closer to understanding Bitwise operations, hopefully! Tomorrow I’ll have a crack at testing to see if a flag is turned on or not. Until then…
Update: Thanks to Jesper Noehr of BitBucket fame for pointing out gaping flaws in my post below (see his comment). I strongly advise you disregard all I have said below, because it will get you into a mess, in much the same way it has me. I’m going to sit down when I have a spare 1/2 hour and try to work out exactly what is going on! Many thanks and big kudos to Jesper, I really appreciate the time you took to correct me.
I have always wondered what the point of Bitwise Operators were,to me they seem to belong to a distant past. However, after reading a couple of great blog posts I have at last an understanding of how they can be put to use, and have started playing around with them a bit (ba dum!).
Jesper Noehr has written about using bitwise operators for a flexible permissions scheme within Python and Jonathan Snook has taken the bitwise concept further creating a great calendar app in Javascript. After reading these I thought I better dive in, and an opportunity came along yesterday when I had to code a flagging system within PHP.
I have recently dusted off an old laptop to play around with and do some “fun” development. One of the things I have done to this laptop is to install a LAMP stack using PHP 5.3 so I can play around and see what’s new and exciting.
I had a quick Google on how to install PHP 5.3 on Ubuntu and found Brandon Savage’s post on the very subject! Whilst he has a great write up it was one or two of his comments mentioning the DotDeb.Org package repository.
This was a breeze to use and in about 5 minutes I have PHP 5.3 running with Apache and MySQL on my clean Jaunty system.
The first thing to do is add the DotDeb.org repositories to your sources list:
$ sudonano/etc/apt/sources.list
# php5.3
deb http://php53.dotdeb.org stable all
deb-src http://php53.dotdeb.org stable all
You will get a warning about untrusted packages being installed but this simply means that the PHP5.3 stuff is not signed, so I typed in “yes” and carried on. Obviously you can cater this line to your specific needs, but this is the basic stack up and running
When it was all complete I tested out my system:
$ php -v
PHP 5.3.0-0.dotdeb.8 with Suhosin-Patch 0.9.7 (cli)(built: Aug 12200918:11:27)
Copyright (c)1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c)1998-2009 Zend Technologies
and tested out my apache installation using a phpinfo() script:
$ sudonano/var/www/info.php
then fired up http://localhost/info.php <?PHP
phpinfo();
?>
and saw as the main header of the page: PHP Version 5.3.0-0.dotdeb.8
I’ve been working on a Wordpress site for a client with one of our developers Tom Hartnell. The design of this particular site was that some pages would need content displayed over multiple columns. This content had to be updatable by the client, as such it could not be hard coded into the template files.
We had a look around and we found a potential solution on this blog post.
We played around with this for a while but found that, whilst it was a good solution, it wasn’t quite suitable for our needs. What we needed was a solution which allowed us to have any number of columns and for each column to contain completely different content. The solution in the post demanded that each column start with the same HTML tag (H2 in the example). We decided to rewrite the function described above, based on the same principals, but updated and improved so it would fit our needs.
To see what the end result is, you can see a demo page.
Been struggling for the past hour or so with method overloading within objects, so I thought I’d write a little not on my blog to hopefully help others and to remind myself.
The premise for this is that I was writing a new database wrapper class to speed up the rather rubbish database module I have been using previously. My plan was to encapsulate all my methods in the wrapper (such as get_table_name() etc) in my class then all others fire off to the ADODB class by PHPlens. My plan was to do this with method overloading, such as:
publicfunction __call($m,$a){return$this->db->$m($a);
throw new Exception('Tried to call unknown method '.get_class($this->db).'::'.$m);
}
However, PHP5 doesn’t seem to support that, which is irritating. After some search on the web I find out that PHP5 doesn’t support real overloading.
So after much effort and searching the web and docs I decide to use the call_user_func_array(&obj) technique.
Finished method below:
publicfunction __call($m,$a){// check the method being called existsif(method_exists($this->db,$m)){returncall_user_func_array(array(&$this->db,$m),$a);
}else{
throw new Exception('Tried to call unknown method '.get_class($this->db).'::'.$m);
}}
Seems to work, so please feel free to use
Note: This post has been copied from the old ibrow.com website, originally posted on 2007-07-04. See this entry for more details
As some of you know, over the past few weeks I’ve been building a prototype for a new web app. For this I decided to try out the Kohana PHP framework to see if it will help speed up development. I chose Kohana primarily because it was light weight and PHP5 only, and I have to say I’m really glad I did. After several weeks hacking around with Kohana (mostly playing admitedly, but I’m almost to the point of having a fully working web app up and running) I have collected a few thoughts on the framework.
Good Points
It is PHP5 only (5.2 and above) so it allows for utilising the full power of OO PHP.
It is light weight.
True auto loading – it’s PHP5, you shouldn’t have to explicate load a class!
The cascading file system – this is a joy to work with. It easily allows you to extend and add to modules, libraries, models and configuration files.
Kohana has greatly speeded up the development of my prototype and has allowed me to focus on the actual functionality of the app, leaving all the boring, repetitive bits of coding to the framework.
I have had to dig about under the bonnet a few times to see what’s going on, and I have been impressed by the clean and well structured code.
The community – behind Kohana there is a small but active and knowledgeable community. I have been stuck a number of times when hacking around with Kohana, and on both occasions I have received prompt and useful replies.
Most importantly it lets you code how you want, without getting in the way, whilst at the same time can take out a lot of the donkey work for repetitive tasks.
Bad Points
This is going to be difficult, but I’ll give it a try
Documentation. From what I can make out it has come on leaps and bounds over the past few months, however, it sometimes isn’t always clear. Also, the tutorial site hasn’t been updated for a good few months now.
Limited number of modules currently available.
However, the above points aren’t deal breakers. Kohana is an open source project, and relatively young at that. This means that I can actively do something about both the documentation (it’s a wiki that anyone can register) and the modules. I just need to find some time and contribute!
Conclusion
As you might already be able to tell, my conclusion is going to be positive. I have really enjoyed playing around with Kohana, it is solid, secure and well designed. Being PHP5 only, not only can I utilise the full potential of PHP, but so can the framework. As said, I’m really glad I chose Kohana, and I am pretty excited about its future developments.
If anyone out there needs a solid, well thought out framework for PHP5, that is backed by an active community, you can’t go wrong if you chose Kohana.
Notes
I have been using Kohana version 2.3 exported from the SVN – details on the Kohana dev site.
Other Reviews
Don’t take my word for it, other people are talking about Kohana too
Review at phoenixheart.net – very recent so a good review of the state that Kohana is in at the moment.
The final part of a review comparing Zend, Symfony and Kohana. This review is about 6 months old, so the comments about the lack of documentation are slightly less accurate today.
I love Ubuntu and today reminded me exactly why. It’s just so easy to do stuff in it!
I run a LAMP development server off my laptop, and today some of the PHP I was writing was throwing up some errors. Unfortunately I hadn’t installed XDebug which makes life so much easier when debugging PHP.
Oh no, I though. I’ll have to download it, install it, update the PHP.ini file. Argh.
But wait…no! I have Ubuntu, all it took was 2 easy steps: