Category Archives: software development

Debugging PHP code to fix a WordPress problem

How do you debug a PHP application? Traditionally developers resort to outputting variable values to HTML, or peering through logs, but why not set breakpoints and step through code just as you would in C# or Java? Maybe because it can take some effort to set this up, as I was reminded today.

I was motivated by an annoying WordPress problem which I’ve blogged about before. For historical reasons, I have a lot of subscribers to an old RSS url which delivers the feed in the now deprecated RSS 0.92 format. I prefer to have a full text feed, and this used to work fine with WordPress, which placed the entire blog post in the element of the feed.

At some point this stopped working, and subscribers got a summary only. In fact, the feed broke completely for a while, after I switched to pretty permalinks; but even after fixing that, I still had the problem with summary items. I tried upping the length of the description, but it was delivered without any HTML formatting so that did not work.

Next I tried the WordPress support forums. There are lots of good folk there; but if you review the posts its clear that many queries go unanswered. That’s nobody’s fault; it is a community, and for whatever reason there seem to be more people seeking help than there are experts with the time to give free advice.

So how about debugging the PHP code and working out what was happening? It seemed a good opportunity to try the latest Eclipse Ganymede, released a couple of weeks ago, along with the PHP Development Tools (PDT). I also figured it would be easier to set this up on Linux, to match what I use on the web server. I used the same Ubuntu on VirtualBox setup that worked well for trying out SproutCore. It worked…

Debugging PHP with Eclipse Ganymede

…but I can’t pretend it was wholly straightforward. Here’s how it went. I installed the latest Ubuntu distro versions of Apache, MySql and PHP – easy. Ubuntu’s Eclipse is not the latest, so I downloaded it from the Eclipse site and used some tips to set it up tidily. Note: make sure Sun Java is installed; I set it as the default JVM. Adding the PHP development tools was more fiddly. I’d half expected this to be part of a standard Eclipse download by now, but it is not, and if you try to install it into Ganymede using the standard update site is does not work because of dependency issues (a big problem with Eclipse). You have to download a 2.0.0 build from here instead.

I’d decided to use the Zend debugger – that’s a separate Eclipse update too, as explained here. Note that even after updating Eclipse, you still have to install the separate Zend debugger server from here, if you want to debug real web applications. I had a few problems getting this working, mainly because of the zend_debugger.allow_hosts directive which you have to edit in php.ini, and which is not brilliantly documented.

I replicated my blog on the Ubuntu virtual box – easy. But how do you get your Eclipse PHP project pointing at this existing code? The method I settled on after a couple of experiments was to start a new PHP project, uncheck the Use default option for project contents, and select the blog directory in /var/www. You then get a scary dialog which observes that files already exist. You can either create your project as a subdirectory, in which case you cannot debug with the existing files, or else pass the scary warning:

Create project in /var/www/blog
(Deleting the project will delete the entire /var/www/blog folder)

I mis-read this at first, thinking it would delete all the files when creating the project. That’s not what it says. Everything was a backup anyway, so I took the plunge; it worked fine. In fact, if you look closely at the screenshot above (click for a full size image) you can see that it is nicely done. You can see the call stack at top left, current variable values, output as it is being generated, and the usual options to step into or over the code.

That said, I did have some problems with Step Into. Just when it was going to be most useful, it bombed out with a message that said Error. If you looked at the detail, that also just said Error. The only fix I found was to set breakpoints in the actual file I needed to debug.

Still, it worked. I found that by adding a single argument to a line in feed-rss.php I could get my full text feed back. I’ve duly reported this in the WordPress support forums.

A couple of observations.

First, I don’t much like the WordPress code. Sorry, because the product is marvelous, but the code seems like a typical PHP tangle. Using pretty permalinks, which I regret, makes it worse.

Second, are there not plenty of developers who use both Java and PHP and would like it to be a tiny bit easier to set up in Eclipse? I’m being a little unfair, since Ganymede is just out and I guess the PDT will integrate better with it soon. Even so, Eclipse is still not quite the smooth plug-in dream that I once hoped it would become.

Note that if you don’t mind paying, you can have Zend Studio which I should think makes life easier. Or perhaps Delphi for PHP.

Sample code for a very very simple VB database application

I wrote a short piece for Personal Computer World about making a simple Windows Forms database application. I did this because I get a lot of enquiries about it, and search hits to this site looking for samples.

The piece is actually in two parts. Part one shows how to do CRUD without any databinding or datasets.

You can download the code here – but please don’t bother if you can already do this in your sleep. The app is for Visual Basic Express 2008.

Part two is about using the VB wizards to create an app with a typed dataset, TableAdapters and so on. The database is SQL Server CE, which is well suited to this kind of application. It is the default in Visual Studio 2008 even though it turns out not to be fully compatible with the wizards. Typical Microsoft – simple, but with enough gotchas to frustrate beginners and keep experts in business.

I ran into another little puzzle while doing the sample. I needed to populate the listbox with both a string value and the ID that is the primary key in the database table. The way I would do this normally is to create a custom class to represent the record, implement a ToString() that returns the display value, and add instances of this object to the listbox. I wanted an even simpler way though, so I decided to use a ListView. This lets you add items that have both a key and a value. You can do this with one of the overloaded Add methods for a ListViewItemCollection, documented like this:

Creates an item with the specified key, text, and image and adds an item to the collection.

The strange thing is, the ListViewItem has no key property. So how do you retrieve the value of the key?

The answer is that the ListViewItem.Name property returns the value of the key. So the key is the name. Why not call it the name in both places? Or the key?

I guess that would be too easy.

The messy world of the Web 2.0 user interface

Verity Stob’s Web 2.0 app diagram is worth a look.

So is it back to plain old HTML+forms then? That won’t do either; your app will look a decade old, and offline will never work.

This is why the current RIA wars are fascinating – particularly since Apple seems averse to runtimes like Flash, Java or Silverlight on its iPhone.

Which leaves what? JavaScript, hélas.

Have you found an AIR app you actually use yet?

Today I downloaded the BBC’s new Adobe AIR application, BBC Live.

This installs as a system tray app on Windows. It’s a beta. Nice little app; but it’s competing against my existing RSS reader which is subscribed to the BBC news feed. The AIR app is much prettier, has images, and lets you customise the feed easily. However, the RSS reader deals with lots of feeds; and I can’t imagine running a separate application for every one. The advantages of the BBC app are rather small compared to the convenience of using a single application for multiple news sources.

Lifehacker recently published a list of the top ten apps worth installing Adobe AIR for. The list had a contrary affect on me, since there is nothing there that I find really compelling. I tried the eBay Desktop app, for example, but much prefer visiting the web site.

So … personally, I’m still waiting for an AIR app to love. But I’d be interested to know what others are running and finding useful.

Technorati tags: , , ,

What’s new in Subversion 1.5

The team behind the open source SCM (Software Configuration Management) tool Subversion released version 1.50 last month. Karl Fogel, president of the Subversion Corporation, says:

Measuring by new features alone, Subversion 1.5 is our biggest release since version 1.0 became available in February 2004.

I am a contented Subversion user, so took a look at the changes. Top of the list is “merge tracking”, though it is described as “foundational” which means that although the basic support is there, there is performance and feature work which remains to be done. From the user’s perspective, the difference is that branching and merging is just easier than before, as explained by Ben Sussman:

Notice how I never had to type a single revision number in my example: Subversion 1.5 knows when the branch was created, which changes need to be synced from branch to trunk, and which changes need to be merged back into the trunk when I’m done. It’s all magic now. This is how it should have been in the first place.

Other changes include sparse checkouts (when you only want to grab a small part of a repository), and changelists, a client feature which lets you tag a set of files under a changelist name and work on them as a group. There are also improvements aimed at making Subversion better suited to large-scale deployments using multiple servers. Subversion is still a centralized rather than a distributed SCM system, but 1.5 is better suited for use in a distributed manner. No doubt the Subversion team is aware of the increasing interest in Git, a distributed system. There are also numerous bug-fixes and performance tweaks. The changes are described here.

I want to move to Subversion 1.5 but it is not that easy. Compatibility is good, in that older clients work with 1.5 servers and vice versa, the main proviso being that you cannot mix several versions of the Subversion client with the same working copy. That is not likely to be a problem for most users.

The difficulty I encountered is that mainstream Linux distributions still have older versions of Subversion in their stable repositories. Ubuntu, for example, has version 1.4.4. My most-used Subversion repositories are on a Debian server, which also has an old version. I don’t want to switch the server to sid, Debian’s development distribution, and mixing packages is often problematic. I could do a manual installation I guess; but instead I will be patient.

I did install 1.50 on Windows, for an intranet repository. I used the Collabnet download. All I needed to do was to inform the installer of the location of my existing repository, and then copy a few lines from the old Apache 2.0 configuration file to the new Apache 2.2 configuration file. Everything works fine. I also updated TortoiseSVN on the Windows clients.

One of the advantages of Subversion (or any SCM) repositories over synched folders like those in Microsoft’s Live Mesh or Apple’s MobileMe (as I understand it) is that you get version history. I regard this as a key feature. The problem with synchronization is that you might overwrite a good copy with a bad one. It is easy to do; it might be caused by user error, or a bug in your word processor, or a failing hard drive. Automatic synch (un)helpfully replicates the bad copy all over. Versioning means you can just rollback to the good one.

Canon’s bad dialog, weak Linux support

While installing Canon’s MX700 all-in-one printer on Windows, I spotted this for my collection of bad dialogs:

do you want to restart the system now?

Hint: if you ask the user a question, it’s good to allow for more than one answer. Even if you close the dialog by clicking the x at top right, it still reboots the system.

I was also interested to see whether the printer works with Linux. Canon doesn’t offer Linux drivers. Nor does it seem keen to hear from customers about this:

Linux printing for other printers

The CAPTCHA test always presents 8 zeroes, which it then rejects as invalid.

I haven’t quite given up.  There are Linux drivers for the Pixma MP520 which are rumoured to work somewhat. When I have a moment I’ll give it a try.

Technorati tags: , , ,

Microsoft accused of reinventing EJB – ouch!

There is a lot of discussion around Microsoft’s object-relational efforts right now. There are a couple of key issues:

  • Is Microsoft really committed to Linq to SQL, or is it shifting its attention to Entity Framework?
  • Is Entity Framework being pushed out before it is ready? A “vote of no confidence” open letter along those lines has been signed by over 300  including more than a dozen MVPs (Most Valued Professionals), experts in Microsoft data technologies.

Now a post from MVP Ian Cooper makes the frightening suggestion that Microsoft is ignoring the lessons of Java’s problems with EJB:

The .NET community had a huge amount to gain from this experience. Ports of Hibernate and Spring offered the community the chance to avoid the mistakes of the past. However, seemingly unaware of the lessons of history the EF team embarked on a project to produce a complex framework, of which persistence is just one aspect, reminiscent of the EJB initiative. So the reaction against the EF comes from its failure to learn lessons that another community has struggled with around complexity and ambition.

Microsoft’s success with .NET has been partly enabled by over-complexity in the Java world. Microsoft’s secret sauce is enabling developers to build stuff that works quickly and easily – which, incidentally, is why I am really disappointed that Visual Studio 2008 is still such a mess for quick database applications.

My own knowledge of the Entity Framework is rather thin. I’ve treated it as a layer that you have to generate in order to use ADO.NET Data Services, a REST API that I really like. It has to be said though – Microsoft’s data story is getting confusing. Roger Jennings is doing a great job of tracking developments.

Windows server compromised by PHP application

Susan Bradley has posted her analysis of how her Windows server was hacked.

This is interesting to me, as Bradley is an expert on server administration and patching; I’m glad she has had the courage to post all these details, thus benefiting the community, rather than pretending the server was down for emergency maintenance or the like.

She thinks it was a security bug in IceWarp Web Mail. This appears to be a PHP application. Although the bug has been fixed, she was running an old version because the new one broke some important features.

The explanation sounds plausible to me. So is it applications rather than operating systems that form the most critical security weaknesses today? Yes, but both are involved. I would be interested to know whether the same bug in a Linux installation of IcwWarp would have been equally easy to escalate to the entire OS.

Technorati tags: , , ,

Adobe’s Acrobat.com REST API

I wrote a piece for IT Week on Adobe Acrobat 9. One aspect of the new Acrobat.com collaboration site that has not received much attention (by way of evidence, the developer forum is currently quiescent) is the document services API. This is a REST API which lets you integrate Acrobat.com services into an application. You can use pretty much any programming language that can talk HTTP. There are some similarities with Amazon’s Simple Storage Service: file upload and download, and management of access control lists based on Adobe IDs (email addresses registered with Adobe). The API reference is here; there are also some wrapper libraries for Java, ActionScript, Ruby, Python and Cold Fusion. No C# yet.

It strikes me as a useful API. For example, imagine you have an application that creates a sales report. The application could upload the report to Acrobat.com and email a group of colleagues with the link.

Another obvious application is a utility to synchronize local and online files. While there are no specific synchronization APIs, you can get the last modified date of a file which would be enough for something simple.

The service will get more useful as other pieces emerge. Flash 10 has a rich text editor with some useful features such as multi-columns with text flow, multi-language and bi-directional support. Put this together with AIR and the Acrobat API and you have all you need to make your own cross-platform offline word processor with online storage. Adobe itself intends to provide this in a future offline version of Buzzword.

Native code client coming for CardSpace as .NET runtime too demanding

I spoke this morning to Paul Mackinnon and Steve Plank at Microsoft, about Information Cards and CardSpace. CardSpace is part of .NET Framework 3.0 and higher. It enables uses to authenticate on web sites by presenting a virtual card, instead of typing in a username and password.

The CardSpace concepts strike me as sound, but as far as I can tell adoption has been minimal. I expressed my frustration; why is it that 18 months after the 1.0 release even Microsoft is not using it to any noticeable extent? I still see username/password dialogs whenever I need to sign into a Microsoft property like MSDN subscriptions or Live Mesh. Actually there is a beta service which lets you sign in with CardSpace – but I believe my point is still valid – how many people even know about this?

I was told that it is still early days and that we will hear more about the Live ID service when it comes out of beta. Mackinnon also mentioned that Microsoft is working on a native code client for CardSpace. Currently users need at least .NET Framework 3.0 which is a huge download and can be problematic. A native code client will be a small download with few dependencies. There is no firm date for release, though it is at least a year away (maybe previews before then).

Technorati tags: , ,