This is one of a series of blog posts about my experience competing in the European WinPHP Challenge 2009. Sponsored by iBuildings, Microsoft and Leaseweb, competitors are asked to build a PHP app for Windows Server 2008 and IIS 7 to showcase the FAST in FastCGI. The winner gets travel and tickets to Microsoft MIX 2010 in Las Vagas in March. My entry is “Give It A REST”, a SOAP <-> REST gateway.
In my last post, I’d reached the point where I had a phpinfo() page in the right place, but had run into a problem with PHP for Windows crashing. In this post, I investigate and solve the crashing problem with PHP for Windows, and then get the rest of the tools in place to complete my development environment for this project.
Getting PHP For Windows Working
Today’s job is to figure out why the PHP for Windows installer has installed a non-working copy of PHP, and whether anything can be done about it, or whether I need to switch to using someone else’s PHP build.
I know from many years of experience that IIS and Event logs on Windows are next to useless when diagnosing problems with PHP on Windows. If you’re used to Apache’s (mostly) helpful errors log, it can be a bit frustrating the first few times. Eventually the bruises from banging your head against a brick wall convince you to find a better approach :)
So instead, I always prefer to fire up a Command Prompt and see whether or not PHP is actually working when run from the command line. This quickly shows a possible cause of the problem:
C:\Program Files\PHP>php-cgi.exe PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_mssql.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_pdo_mssql.dll' - The specified module could not be found. in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\ext\php_pdo_sqlite_external.dll' - The specified module could not be found. in Unknown on line 0
This is caused by a missing DLL – ntwdblib.dll – which the MSSQL extension needs to use in order to talk to Microsoft SQL Server. It looks like the PHP for Windows installer doesn’t distribute this required dependency, and neither does it check to make sure the dependency is satisfied before allowing you to install PHP.
The best way to get hold of ntwdblib.dll is to copy it from wherever you have installed SQL Server. That way, you can be sure that the DLL is compatible with your copy of SQL Server. Back in the SQL Server 2000 days, you could also get it by installing the SQL Server Client Tools onto your web server (always a good idea; very handy being able to fire up SQL Server Management client to diagnose database connection issues when working in firewalled DMZ environments).
(If memory serves – it’s been 18 months since I did this for a living – the need for ntwdblib.dll will finally go away when PHP has a modern extension that uses the SQLDMO or later API. The MSSQL extension uses TDS to talk to SQL Server currently. Unfortunately, TDS was designed for Sybase and lacks support for useful features in SQL Server 2000 and beyond like unicode. Of course, there’s a downside; switching from TDS will make it almost impossible to use Linux webservers against an SQL Server back-office setup).
The quick fix is to edit php.ini and disable those extensions for now. With that done, http://localhost/phpinfo.php now works. Woohoo! Test case satisfied :)
Improving On PHP Performance
One of the best ways to boost the performance of your PHP scripts for free is to download and use Zend Optimizer. If you haven’t heard of it before, Zend Optimizer analyses your PHP code when it is loaded into the PHP scripting engine, and rewrites the bytecode to be more efficient. Zend have made it available as a free download for several years, but now it’s also available as part of the larger Zend Server bundle, where it is known as Zend Optimizer+.
Zend Server’s copy of PHP also comes with APC (the bytecode cache that will be bundled by default with a future version of PHP; I’ve lost track of whether that will be PHP 5.3 or PHP 6), which also boosts the performance of your code. This is something you have to download separately if you use the PHP installer from www.php.net. And it’s also worth looking at Zend Server for its simple web-based control panel to manage your PHP configuration, and (if you buy a license for the product) for its ability to monitor your PHP scripts to see what needs your attention.
I was very pleased with how easy it was to install and configure Zend Server. Like the community PHP installer, it doesn’t seem to support anything other than the default web site, which is a serious oversight for use in larger organisations, but otherwise its ease of use is exactly what your average Windows PHP dev would appreciate.
Interestingly, when it comes to databases, Zend Server doesn’t include the PDO extension for SQL Server. I had a very quick go at taking PHP.net’s build of pdo_mssql and installing it into Zend Server’s build of PHP, but unfortunately Zend Server reported that the extension failed to load. The problem is that PHP.net’s release of PHP (and extensions) is built with thread-safety on, but Zend Server’s release of PHP is built with thread-safety off. It’s not for me to say which one is right, but it does mean that the two different releases appear to be binary incompatible.
And that is something that can’t be good for the PHP community on Windows overall.
(PS: make sure you un-install the community version of PHP for Windows before installing Zend Server. If you use Command Prompt to run Zend Server’s php.exe, it goes and loads the php.ini file from the community version of PHP first, which created some interesting problems whilst preparing this article. Basically, if you manage to screw up PHP so it can’t run, the Zend Server control panel stops working precisely because it is written in PHP. A bit of an egg/chicken situation there).
Choosing A Database Server
Most web-based applications today use a RDBMS to store and retrieve their data. Microsoft have made a baby version of their heavyweight SQL Server product available for developers to work with.
Microsoft has made it easy to get SQL Server Express through their Web Platform Installer. They currently have a beta 2.0 release out that also includes bundled PHP. However, I can’t recommend this approach at the moment because of the licensing terms, which state that this is pre-release software that you’re not allowed to use in a “live operating environment”, and that your rights to use the software expire at the end of June 2009 or whenever a commercial version of the platform installer is released – whichever happens first. I don’t have a problem with closed-source software, but I do object to software with expiry dates. (I accept that I’m in a minority on this).
SQL Server “Express” is a fat lady … 218 MB in size. Definitely not something I can download over mobile broadband whilst traveling to and from the office! By contrast, MySQL RPMs for RedHat Enterprise Linux 5 weighs in at a positively svelte 28.2 MB – almost a tenth of the size. And it comes with more features. But, as I’m actually quite a fan of SQL Server, I’m going to add it to my dev environment.
The list of download options might be too cryptic for some developers:
For 32-bit systems, download the _x86_ file. For 64-bit systems, download the _x64_ file. Perhaps Microsoft might want to put suitable descriptions on this list, for folks who aren’t sure which file is right for them?
Oh, and don’t forget to download the dependencies listed earlier up the page; they’re not present on a fully-updated Windows Server 2008 install. I swear, it’s just as bad as using a RedHat box ;-)
Choosing A Version Control System
If you don’t use one already, you should. Version control systems are an essential part of any development environment, even for one-man hobby projects such as this one :)
My VCS of choice is git. Subversion runs well on Windows, and has for years, but I’m very mobile and absolutely need the ability to make commits whether or not I have internet access at the time. (Walk in my shoes for a week, and you’ll find the idea that we’re now “always connected” somewhat laughable). I don’t make anywhere near full use of git’s many excellent features; like many folks I’m waiting for the books on git to appear later this year.
There’s a port of git for Windows from the msysgit project on Google Code. I haven’t used it before, so it’ll be interesting to discover how well it works.
Choosing A PHP IDE
I’ve used phpEclipse on Windows for PHP development for several years, but the guys at worked convinced me to switch to using the Netbeans nightly builds instead. The demise of Sun earlier this week has cast a shadow over whether or not Netbeans has a future (Oracle in the past has not been a supporter of Netbeans), but until someone pulls the plug, it’s my IDE of choice. As with git, I’ve never used it on Windows, so it’ll be interesting to see how well it works.
Using Netbeans also means downloading Java – which you need to do before you can install the PHP bundle of Netbeans. Downloading Java for Windows is a two-step process; you download a small installer first, and when you run the installer it goes off and downloads the complete Java standard edition as a second step. I’ve never understood why Sun do this; perhaps it’s their way of ensuring that you always have the latest version of Java available when you actually do the install? Answers on a postcard please :)
Netbeans currently only supports the excellent xdebug extension for PHP for single-step debugging. It doesn’t support Zend Server’s own zend_debugger extension. (Does anything, other than Zend Studio?) I had no luck at all getting any of the xdebug DLLs working with Zend Server; both the thread-safe and non-thread-safe versions cause Zend Server’s copy of PHP to crash. I haven’t actually tried it, but I expect that the xdebug DLL works absolutely fine with the PHP for Windows from php.net.
Hrm … it’s been a tricky decision, but for now I’ve decided to stick with Zend Server, because I want to evaluate how useful its built-in monitoring is. If the lack of xdebug becomes a problem, I can always setup a second website under IIS w/ PHP from PHP.net and just switch between the two.
Completing The Development Environment – Visual Studio
To finish my development environment, I need something for building & debugging .NET code. (Part of my application needs to be built in .NET). Again, thanks to the folks from Microsoft who attended the PHP UK Conference 2009, I have a 1 year evaluation license for Visual Studio 2008 Standard Edition. From the install screens, I’m led to believe that updates for Visual Studio are downloaded using Windows Update. But Windows Update states that there are no updates available.
I’m having a bit of trouble believing that :)
The Development Environment – Recap
With the development environment now up and running, I thought it would be useful to recap on what the full environment looks like.
- Second generation MacBook Pro, using a Samsung PB22-J 256GB SSD.
- Microsoft Windows Server 2008, running inside VMWare Fusion.
- Zend Server, running on a free trial license.
- Mozilla Firefox + Firebug & FirePHP, with Internet Explorer consigned to the trash can :)
- git for Windows from the mysgit project on Google Code.
- git repository replicated up to github.
- Netbeans nightly build, using the PHP bundle.
- Visual Studio 2008 Standard Edition.
Note that I have chosen not to spend money on anti-virus software for Windows, because the VM will be used for a one-off project and then destroyed. If Windows was your regular dev platform, you’d need to invest in anti-virus and anti-spyware software, and pay a regular subscription in order to keep it up to date.
With downloaded installers and temporary files deleted, the overall size of the Windows Server 2008 virtual machine now stands at 10.54GB according to OS X, and 11.3 GB according to Windows Server 2008. I’m left with only 4GB of free space under OS X, and will be spending the evening looking for ways to free up a bit more space!
How do I feel about the development environment? A little disappointed, if truth be told. Under Windows, I’m largely stuck with building the development environment from the pre-built components other people have made for me. That’s fine, until combining those components reveals compatibility and/or quality problems.
It’s worth pointing out how useful Twitter has been during this work. I’ve had no less than three folks from Zend responding to my tweets, including their CEO and the Zend Server product manager. I’m not a Zend customer, nor am I known to be a Zend advocate. At work, we spend more with organisations like VMWare and Netsuite than we could ever need to spend with Zend, and yet their support simply doesn’t match up to how responsive Zend has been.
With the development environment built, it’s time to turn my attention to the app I’m going to build. Before I write any code, I need to sketch out a design for the app, and probably do some R&D on the components that will be completely new to me. I’m unlikely to write any PHP code for some time yet.