Archive for category Development

Cherokee vs Apache : An alternative web server

As I have been developing for the web for over a decade, I have become comfortable with tools and technologies which have helped me get the job done. Some of these technologies I have seen evolve and progress into what are now essential and very powerful solutions. I have established an affinity with many of these tools and without doubt the Apache web server qualifies as such a technology for me.

Using Apache over the years as my main web server, I have produced all types of software solutions for many diverse businesses within many different industries.  Apache has served me well and I am an advocate of the old saying ‘If it’s not broken, why fix it’ (within reason). Until recently that is….

Over the past few years in the distant background I have heard mention of Cherokee as being a viable alternative to Apache, with some claiming it offers benefits. These have been whispers registering in the distance, but didn’t sound interesting enough to pursue and invest my time as Apache was doing it’s job well. However recently these whispers became a little louder following a few conversations with a work colleague singing Cherokee’s praises. What caught my attention most from the conversations wasn’t simply that Cherokee was faster, but that Cherokee was much easier to use and quicker to configure. As I don’t like ‘shaving Yaks‘, my approach was that if I start hitting obstacles, I’ll leave it for another day which contains more than 24 hours; after all Apache is working well for me.

My local lightweight development environment consists of a Linux VM (Fedora) which I operate using VirtualBox. I deliberately reduce my VM’s resource allocation such as setting my RAM allocation to 512mb on my VM to encourage good code and to identify memory leaks. I have the other usual stuff setup such as Zend Framework, xdebug, MySQL etc. This was the machine which was going to carry out the test switch from my trusted Apache to Cherokee.

I disabled Apache and installed Cherokee using the supporting well written user guide. Within minutes Cherokee was up and running and there we NO problems! I was expecting some configuration hurdles as per usual, but nothing. My sites were running as if I was on Apache and there were no noticeable differences. I configured the logs to act as the same as Apache and all was set.

As I delved deeper into the setup guide I was pleasantly introduced to Cherokee’s administration interface. This was a pleasant surprise as I’m so used to hard coding configuration information into httpd.conf. This interface presents configuration options for all the usual server settings such as ‘Virtual Servers’, ‘Directory Sources’, ‘Logging’, ‘Security’ etc. The beauty of this is not that it’s simply a little prettier than the command prompt, but it’s quicker to use. You can configure your server settings simply and quickly which are two good properties to have on your side.

Although I was impressed so far, the remaining challenge that Cherokee must live up to for me is it’s speed advantages. In the spirit of keeping things simple and to get a loose overview on performance advantages I thought I’d simply use ‘Zend Controller’ which is bundled with ‘Zend Server CE‘ to test how many requests per second both Apache and Cherokee could handle in turn upon my humble local virtual machine. From these tests I obtained the following results :

Apache Web Server Results

Zend Controller testing Apache requests per second

Apache requests per second on local VM

Cherokee Web Server Results

Cherokee web server

Cherokee requests per second on local VM

As you can imagine I was quite impressed with what the results presented. The results roughly show that Cherokee could handle 2.5 times more requests per second that Apache! That is no small margin!

What does this mean for me going forward? Well the first things that went through my mind understandably were cost and time savings. Potentially this could reduce the need for more hardware. Less hardware means less purchase costs and less maintenance time. Obviously there are other factors to consider before jumping the gun, but Cherokee certainly has my attention now. I will definitely be including Cherokee in my future plans. An exercise well worth the time.

If anyone reading this has done the switch, please feel free to reply to this post with any feedback

Related Link : alobbs.com

, , , , , , , , , , ,

3 Comments

Scrum Teams – Lean, Mean developing machine

In the past few years I have read about Scrum, Agile and watched many a tutorials and short videos on the benefits and how to implement it in the work place. After watching from a far I managed to get my hands dirty and get involved with applying it in the workplace. Over a period of many months, bit by bit we have implemented it into our development environment. I have to say it hasn’t been easy and it’s only possible with support from the business in my opinion. Developers and testers were the first to welcome the change as it empowered them and gives them recognition for their efforts as well as control. The business took longer as the change is drastic and involves them a great deal more in product development. However once involved, the agility and development speed and project transparency becomes something recognisable and desired.

During this implementation a common emphasis raised via many sources is to keep the teams small and focussed. Many comparisons have gone through my mind, including why and how to select certain people and create teams. One of the best comparisons and inspirations to make sense of this is to compare the military structure. The comparison that strikes me is that traditional waterfall teams which consist of large scaled divisions that progress in linear fashions with a great deal of resources and structure. They take a great deal of planning, authorisation and strategy to get momentum. When the momentum has started, it’s difficult to stop and change direction. These can be compared to a military invasion, invading in stages as one large force following months of planning and financial investment all moving towards a strategic location in mass. Scrum teams to me represent a different dimension to this, I see scrum teams as small, more precise well equipped units similar to special forces. Smaller teams which are empowered, focused and take more control over their missions who often find themselves more capable and agile. They can be deployed into many different environments, are quicker to adapt and are in and out of missions quickly, sharply getting maximum results.

Special Forces Scrum Development Teams

Like special forces, scrum teams are best kept small and varied. Many sources suggest that a team should consist of no more than 8 people to keep the team dynamic and I agree with that. Anything more and like most larger groups, you risk losing communication and focus.

When you have the balance in place and the team become used to this way of working, the business will benefit and get results. Results which require less investment over time and able to see the impact and return of having small, specialist teams. After all, we have all seen renditions of the battle of Thermopylae, which is basically a tale of a small force with superior weapons, training and passion taking on the might of an army. Although not a direct comparison I think there are similarities in structure do compare in very distant kind of way. The strategy depends upon the business’s plans and objectives, but ultimately every business wants to get more from it’s resources and wants to be able to be quick to respond to environmental conditions to stay ahead of the game.


, , , , ,

4 Comments

Common Misconceptions of PHP

As we have just rolled over to 2010 I thought I would compile a list of 4 common questions often raised against PHP from people within the IT industry (no particular user groups). Each of these 4 statements were mentioned to me within 2009, but stem back many years in some cases. Some of these questions demonstrate plain ignorance in some cases, others just a little confusion as a result of lack of understanding or exposure. Therefore I hope this contributes to clearing up some obvious misconceptions by my provision of some brief answers.

  1. PHP is not a secure language
  2. Believe it or not this was stated to me by a highly ranked person within the development community. I was very surprised that such a statement was put forward considering PHP is a scripting language and security is not a definitive answer, but an on going process in which every facet of IT must undergo constantly to remain secure. To clarify this is a case of blaming poor workmanship on the tools. Although some tools are better than others, in no way do I believe this statement to be true. PHP can be as strong as the best of them in terms of security and some of the worlds most secure systems including many systems of the financial services industry as an example which hold vast amount of sensitive information can be found to be written using PHP. When using a tool to build something, the end result is that of the craftsman effort, ability, knowledge and experience. Keeping the argument of operating system security out of this which would be hosting PHP, to obtain security you need good, experienced and security aware developers. I personally believe this misconception often raises it’s head because of other languages restrict development to the framework or coding environment and developers within these environments don’t have to confront some areas of security as a result of this. I don’t think it’s good for developers to rely upon security being dealt with away from their application by making it someone or something else’s responsibility. A good craftsman will make it their job to be aware of system security and test their application before release as well as include continuous monitoring and alerting tools to support the application. Obviously there are those which specialise in such areas and their knowledge should be referred to in times of doubt or curiosity via supporting texts and communities. PHP is as secure as the developer’s knowledge and testing/release procedure involved with it as with most other languages.

  3. PHP doesn’t have good support for OOP
  4. I’m surprised that some people still think this. Before the release of PHP5 including the Zend 2 Engine, which was 13/07/2004 this would have been true. However please keep up people, we are in 2010 now and OOP support for PHP has been in place for over 5 years! I haven’t written procedural code for years with the exception of the odd testing script and procedure. There are great libraries available as well for those looking to extend OOP ability including such libraries as SPL, PECL, PEAR to name but a few. There are also some very fast moving and powerful frameworks available fully supporting OOP including such Frameworks as Zend Framework, Symfony, CakePHP, Codeigniter. These are also become very popular and demand for such frameworks from the workplace is rapidly increasing (see my other post).

  5. PHP is slow
  6. Yes believe it or not I have heard people claim this. PHP is pretty damn fast as a scripting language written in C. If people say PHP is slow, I don’t believe the have looked at the problem or debugged their code well enough. There are so many factors that influence speed such as the OS, memory, debug code, logging scripts, the implemented code, other applications on the server etc. If your PHP code is running slow, debug it and find the problem. It’s likely that the problem could sit with any of the above or it could be badly written code. There are good debug tools out there such as Xdebug which could save you some time finding the problem. Remember PHP is so versatile you can even extend it in C. If you are doing something very complex in PHP and by taking it down a layer might reduce some of the functions taking some time, you have the option to write an extension if needed. I personally have never had to do this, but have seen it done for a workplace specific extension and it worked perfectly and very quickly.

  7. PHP is an amateur language
  8. With full OOP support and factoring in that it’s one of if not the most widespread scripting language and as mentioned briefly in point 1 above, you can find PHP in almost all industries. Now I am not one to suggest the best technology is the most widespread (no names mentioned). However if PHP was a amateur language why is it so popular in so many professional industries which demand professional results. You can write pretty much anything you want using PHP and it can be as simple and complex as you want it to be. I have used Java quite a bit in the past and often find myself using the same code design texts to reference my PHP objects as my Java objects. I even apply the same design pattern sources for both languages. An example is the built in observer pattern interface in Java, (java.util.Observer) PHP also has this (SplObserver). Again I feel that stating that PHP is amateur is missing the point that PHP it’s a tool for the job. If amateurs use PHP you might get amateur results by the same token if professionals use it you get professional results, which is obviously the same as any other language.

Overall I think some of the questions or statements raised above are raised as a result of lack of understanding. As with most things in life some people scratch the surface of an area of interest and call themselves experts. The same experts make such judgements which create barriers for others. This could reading a text titled ‘Learn PHP in 24 hrs’ then calling oneself an experienced programmer or taking your driving test after a couple of lessons in a controlled environment and calling oneself an experienced driver confident enough to race with the likes of ‘Jenson Button’ and expect to win. Personally I have been using PHP for over a decade now and I am still learning new things everyday, particularly through exposure of different implementations. The language is moving fast with PHP6 arriving soon as well as many new and exciting related projects becoming available such as the array of frameworks which provide common interfaces to integrate with many different technologies. I would encourage anyone to look under the bonnet and get to know PHP in more depth and hopefully you will see the true power and capabilities of it.

, , , , , , , , , , ,

3 Comments

Installing PHP5 on Leopard with pdo_mysql & iconv() support

I recently took the plunge a level further into the Mac world and purchased an iMac running Leopard. Although I have been running a Macbook for years, I decided that my main machine which I develop on was going to be something I have to spend less time configuring than my previous Linux machines (Although my servers will remain Linux). My main goal was to get a slick dev environment running PHP, MySQL and Apache.

Being naïve, I expected Leopard to provide me with a suitable stable release of these technologies straight out of the box, after all Leopard comes with Apache, MySQL and PHP right? Well this maybe true, but this is not exactly what I expected. Soon after building my little world of development I realised that the distribution was insufficient. Disappointingly I learnt that the PHP distribution was missing ‘pdo_mysql’! How could they have missed this I asked myself? The extent of use of ‘pdo_mysql’ usage should have made this a fundamental module, even Zend Framework, one of the worlds largest PHP Frameworks uses this as a standard. Anyway this is the crossroads, do I recompile the distributed version and risk the Apple support or do I download and compile my own version. Well I thought, lets install it via macports, that will save me a bit of hassle. This also meant that I could maintain a separate series of installs to what came with leopard.

After downloading and installing macports I installed the following:

sudo port install php5 +apache2 +mysql5 +pear

port install jpeg

port install libpng

port install freetypeport

port install libmcrypt

After updating my apache configuration located ‘/opt/local/apache2/conf/httpd.conf/’ to suit my needs including pointing the my sites directory located in ‘Users/craigstrong/Sites’ I thought I’d give it a whirl on my web apps.

sudo apachectl restart

Everything seemed to work fine. I loaded up a few static pages from one of my Zend Framework projects, then I thought I’d try my login script. Boom! Guess what, no ‘pdo_mysql’ module installed. Arrggghhh!

Well off I went to get PHP 5.2.9 as this was the most stable recent release at the time. I convinced myself this is the solution I should had tried first. I downloaded this version and strapped myself in for a bit of compiling.

Within my extracted directory ~craigstrong/Programs/PHP-5.2.9 :

./configure
\
–prefix=/Users/craigstrong/Programs/php-5.2.9/
\
–with-apxs2=/opt/local/apache2/bin/apxs
\
–with-xsl=/usr’ \
–enable-mbstring
\
–with-gd’ \
–with-jpeg-dir=/opt/local 
\
–with-png-dir=/opt/local
\
–with-zlib-dir
\
–with-curl=/usr \
–enable-sockets \
–enable-exif
\
–with-mcrypt=/opt/local
\
–enable-soap
–with-mysql=/usr/local/mysql \
–with-pdo-mysql=/usr/local/mysql/bin/mysql_config
\
–with-mysql-sock=/tmp/mysql.sock
\
–with-freetype-dir=/opt/local
\
–with-openssl=/opt/local \
–enable-cli

The configuration went well, so I thought lets start compiling and run the following:

make

Followed by :

sudo make install
sudo mv /usr/bin/php /usr/bin/php.distro
sudo ln -s /Users/craigstrong/Programs/php-5.2.9/bin/php /usr/bin/php

All seemed to go well, and I went through my application again. This time when I go to the login form I was greeted with a new problem saying that the application could not find the function iconv(). Absolutely great I thought, another obstacle! After a bit of reading around this problem I found this link confirming my problem was real and what actually was attributed to a problem in the configure script on Leopard (http://www.mail-archive.com/php-bugs@lists.php.net/msg120323.html). I made sure to add the following 2 lines to the configure script pointing at my macports location.

–with-iconv=/opt/local
–with-openssl=/opt/local


As soon as I got to the ‘make’ command I was greeted with the following output:

Undefined symbols:
\\”_iconv_close\\”, referenced from:
_php_iconv_string in iconv.o
__php_iconv_strlen in iconv.o
__php_iconv_strpos in iconv.o
__php_iconv_mime_decode in iconv.o
__php_iconv_mime_decode in iconv.o
__php_iconv_mime_decode in iconv.o
_zif_iconv_substr in iconv.o
_zif_iconv_substr in iconv.o
_php_iconv_stream_filter_dtor in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
\\”_iconv_open\\”, referenced from:
_php_iconv_string in iconv.o
__php_iconv_strlen in iconv.o
__php_iconv_strpos in iconv.o
__php_iconv_mime_decode in iconv.o
__php_iconv_mime_decode in iconv.o
_zif_iconv_substr in iconv.o
_zif_iconv_substr in iconv.o
_zif_iconv_mime_encode in iconv.o
_zif_iconv_mime_encode in iconv.o
_php_iconv_stream_filter_factory_create in iconv.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

Well at this point I was getting more annoyed and again started cursing Apple for not sorting this out with the distribution of Leopard. Have to blame some one I thought.

Anyway after a long think a good time reading around the web I convinced myself to download php5.3 and go through the process again. I went through the same process of downloading, configuring and compiling it using exactly the same configuration script as above. I wasn’t expecting a high chance of success with the previous events. However to my amazement it worked. I went through my site and I finally achieved my goal of having PHP with ‘pdo_mysql’ and ‘iconv’ support! Although frustrating following the process, it was satisfying getting a result.

As I use Zend_Framework the only thing that needed to be resolved is that my date() function was throwing an error saying something on the lines of ‘best not trust the systems timezone’. I then added the following function to the bootstrap date_default_timezone_set(’GTM’) and my problem was solved. I now have a development environment I can enjoy.

Useful Links Relating to this post :

  1. http://seancoates.com/php-5-2-5-on-leopard
  2. http://www.mail-archive.com/php-bugs@lists.php.net/msg120323.html
  3. http://drewish.com/node/110
  4. http://www.malisphoto.com/tips/php-on-os-x.html

, , , , , ,

1 Comment