The lead developer at Mosaic, Brighton with a passion for web application development and motorcycles.
Quite often when you are working with legacy code you will come across a mess of globals. Every single method will make use of the same global instance of the database class for example. So where do you begin to work with this massive impediment?
Logging is a great way to see what methods and classes are being used by you application and where. To achieve this you would normally need to add a logging call to each and every method in the code base. Clearly this would be incredibly tedious and time consuming.
This is where a proxy object can be implemented to save time and centralise the logging functions. The basic idea of a proxy object is that it will be instantiated in place of the actual class and the proxy will delegate any calls through to the original class. For the purposes of this example the original class will be called Database and the proxy object will be called LazyLoadingProxy.

I needed to add a new port forward to a router, but I did not have access to the web interface through a graphical browser. Attempts to get in using Lynx stalled as it seems the router will not serve up the frames in the interface independently of each other and it kept issuing 404 errors.
Either way I had to use the telnet interface using the following command (replace 192.168.1.1 23 with the IP address of your router):
telnet 192.168.1.1 23
This is fine except that Draytek have absolutely no documentation available for the commands. So to discover the correct command I had to go through all the available options (and sub options and sub sub options) as it was not immediately clear to me which option port forwarding was hiding under. To give you an idea here is a list of the top level options (run the `?` command to get this view):
> ? % Valid commands are: adsl bpa csm webf ddns ddos urlf kw exit fe internet ip ipf log mngt port portmaptime prn quit show srv sys tsmail upnp vigbrg vlan vpn wan wol qos
The option we are interested in is `srv` which has a number of sub options but we are only interested in `nat`. Now we have yet more options but lets just stick with `portmap`.
I am not sure, but I think xammp has changed recently and no longer includes phing by default and therefore you will need to do a search to find where PEAR installed phing. The path you have mentioned was the default location of phing when I wrote Installing Agavi on XAMPP Windows, but I would imagine you could now find it somewhere in C:\xampp\php\PEAR\
The other article to which you refer is A Good Windows Development Environment and Ubuntu Virtualbox. It should be enough to get you going and I think it is better have Agavi running in more dedicated server environment (in a VM) than running it on a Windows desktop. Hope that helps.
When working in a team it is very useful to have a central web server with multiple environments and a configuration as close to the live server as possible. This can be a bit of a nightmare though if you need to setup a new VirtualHost container in Apache every time a new project is brought on or when a developer wants to work on a version of the site in their own environment.
The good news is that this can all be handled automatically and new sites can be setup by simply adding a new directory to the file system. There are at least two ways of getting this going; the first of which is the mod_vhost_alias module for Apache and the second is enabled via mod_rewrite. I prefer to use the second method as it is more flexible and it allows you tap into the ability of mod_rewrite to introduce environment variables and redirect requests (this is particularly useful for robots.txt - you’ll see).
The Apache2 Manual does have a very good page dedicated to overcoming this problem, but I will be sharing with you all the settings I am using which you will need to stop Google et. al. from crawling your sites served from the staging environment for example.
External Link: Redis: under the hood (internals)
I was curious to learn more about Redis’s internals, so I’ve been familiarizing myself with the source, largely by reading and jumping around in Emacs. After I had peeled back enough of the onion’s layers, I realized I was trying to keep track of too many details in my head, and it wasn’t clear how it all hung together. I decided to write out in narrative form how an instance of the Redis server starts up and initializes itself, and how it handles the request/response cycle with a client, as a way of explaining it to myself, hopefully in a clear fashion.
(Source: twitter.com)
Installing via the pecl command can be a pain on Redhat. First off all you will need to install the php-devel package:
yum install php-devel
Then you will need ensure that the PEAR/PECL installer is at the latest version so as root run:
pear update-channel pear.php.net
pear upgrade pear
You may need to force pear to upgrade itself by using:
pear upgrade —force pear
I had to use the —force option because my version of PEAR was so old that the installer thought my version of Tar_Archive might not have been up to muster. It was however.
With all this in place you are ready to attempt to install your chosen extension:
pecl install ssdeep
If you get something like the following back:
/usr/bin/phpize: /tmp/ssdeep/build/shtool: /bin/sh: bad interpreter: Permission
Then it is likely that your temporary directory is mounted in a safer noexec state, which means that you cannot execute scripts within the /tmp directory. To test this you can put a simple bash script into your /tmp directory and chmod it with +x. I used the following bash script:
#!/bin/bash
echo “SIMON”
If you do not get SIMON back when you execute the file, but an error like “/bin/sh: bad interpreter: Permission” then the directory is set to noexec.
There are a few ways to overcome this with the easiest being to:
mount -o remount,exec /tmp
pecl install ssdeep
mount -o remount,noexec /tmp
There are a variety of other ways to get this working documented in the Media Temple wiki pages if the above technique does not work for you.
External Link: Forcing NetBeans to Use Unix (LF) Line Endings
NetBeans usually uses the operating systems default line ending when creating a new file (it establishes this by what the JVM tells it). So for example in Windows it will automatically use CRLF and in Unix it will automatically use LF. This behaviour has its advantages, but sometimes you want to to be specific about the line endings you need.
To do this you can add the following switch to your call to the NetBeans binary. On Windows this would be done on the shortcut by opening its properties and adding the switch at the very end of the Target line.
-J-Dline.separator=LF
Whilst this is handy a proper setting in the preferences of NetBeans would be preferable as it could then easily be backed up and taken from machine to machine. Vote for the issue on the NetBeans bug tracker.
Whilst developing a PHP extension recently I spent quite a bit of time researching exactly how to create an extension, the best practices and the DocBook format of the PHP manual for documenting the extension.
By the time I finished writing the extension I had found some very good resources both on the web and in print.
Online Articles or Websites:
Printed Books:
Information on Documenting PHP and PECL Extensions:
Also worth a mention is the ability of the new PEAR2 Pyrus installer to generate a skeleton for you to build your PECL extension upon - see the generate-ext section of the manual.
Pyrus can also be used to package your extension up for release using the pickle command.
For more help there is a PECL mailing list and IRC channel (#php.pecl on efnet), both of which are in the support section of the PECL website.
Whilst not strictly for PHP extensions the Autotools: a practitioner’s guide to Autoconf, Automake and Libtool book by John Calcote on the Free Software Magazine is very useful reading for an understanding of the build process involved in extension writing.
There is also the GNU Manual for Autoconf and GNU Autoconf, Automake, and Libtool by Gary V. Vaughan et al.
External Link: The PHP ssdeep Extension is Now in PECL
This means you can now install it easily by simply running:
sudo pecl install ssdeep
There is also proper documentation in the PHP manual which can be found at php.net/ssdeep.
For more information on the extension either see the PECL project page or the ssdeep PHP/PECL extension’s homepage.