How Microsoft Made PHP Suck Less on Windows
As yet another demonstration of Microsoft's seriousness about participating in the open source community, it's hard at work to make PHP run better (dare we say really well?) on Windows. During last week's Open Source Convention, I spoke with the dude in charge of making that happen.
[ See also: Convincing the Boss to Accept FOSS ]
For years, PHP developers might develop on Windows but never deploy on Windows. And for good reason, explains Garrett Serack, the open source software developer at Microsoft who's involved with the company's Open Source Technology Center. "If you banged on [a PHP application] too hard on Windows, IIS would crash, and nobody could tell why it died," he says. The existing PHP driver was based on old protocols; its performance was "not great" because, Serack says, the PHP community lacked the technical information necessary to improve it.
As you might imagine, that presented a problem for Microsoft, since its own developers knew that a third of Web applications are written in PHP, Serack says. When the company realized that developers weren't using PHP on Windows because really, they couldn't, some inside Microsoft were ready to make a change. Doing so has consumed most of Serack's time ever since. (You can find links to the latest PHP for Windows code at windows.php.net.)
The first to encourage PHP-on-Windows improvements was the SQL Server team, which wanted to enhance existing open source applications to work better with the SQL Server drivers. (That is, they would like developers deploying PHP apps on Windows to use SQL Server rather than MySQL, or at least to consider doing so without generating gales of derisive laughter.) The first new-and-improved PHP drivers for Windows were released in October 2007. The open source community said — in a nice way, Serack insists — "Your driver sucks." So the SQL Server team went back and redid it, in direct response to what people actually wanted.
Naturally, the team wanted to release the code changes back to the community. Explains Serack, that meant a lot of conversations with Microsoft's legal counsel to get permission to contribute the code. Developing a legal process took months, since releasing code as open source is still a very new idea to the company. But it's not a unique challenge; as Serack points out, "Every large company that has contributed to open source has developed a [legal] process similar to this."
Anyway, at last year's OSCON Microsoft submitted code to ADOdb (a database abstraction layer for PHP) and a couple of others. "About this time last year, the folks in the Open Source Software Lab wanted to accelerate the development of PHP on Windows," Serack says. Pierre Joye (already a PHP committer) had some free time, so Microsoft enabled him to work (with Serack) on the specific goal: improving PHP on Windows.
Meanwhile, Serack got started by improving the Windows PHP build process by scripting it from scratch. As with so many other projects, he had to build tools to build more tools. "I wanted to include all the DLLs," he says. He built a trace tool to track what was being built, and created brand-new Visual Studio project files. "No more
make files and custom batch scripts!" Serack sighs happily.
Follow ITworld on Twitter: @IT_world
Just by doing that, the core interpreter benchmark came out to within 1% of the speed of PHP running on Linux. Next step: Serack built an instrumented binary and then ran real world data (that is, real PHP scripts) through it, feeding the profiled data to the compiler. (Profile guided optimization is among the cooler things in Visual Studio, my .NET developer friends have assured me for years.) That made the core interpreter speed 18% faster — without changing a line of code. Just by changing the build process.
Getting the build process in shape was not a trivial task. It took a while to get every single module compiled with the same — and right — settings. "If one library used different optimization, it was out of whack," Serack says. "There were 35 of these things."
Plus, he said, Joye replaced a lot of old libraries. The POSIX emulation libraries, for example, were about a decade old. Creating brand new versions of all the dependent libraries had a big effect on performance, but also had a huge impact on reliability, Serack says.
That's not to say the job is completely finished. (What open source project is? Or development project is? Like writing novels, code is never finished, only abandoned.) "There's still things we're working on," Serack says. For example, some things are done differently with the file system on Linux versus Windows. Plus, he admits, "In the real world apps, we're still 'getting there' in terms of performance. But at least now we have this really stable platform."
I can see your face. (My secret journalist powers let me do this sometimes.) You are thinking: "Microsoft? Open source? Commitment? You must be joking." Serack isn't naive about the attitude either. In fact, the company intentionally kept a low profile for a while, while it worked on the PHP-on-Windows enhancements. "We didn't want to step on people's toes," he says. "Our goal is to get PHP running great on Windows. We want to contribute [to PHP], not fork it. This is not even a consideration. It's to go into the community — to participate, not drive-by code dumps."
Serack's goal is simply to make PHP run better on Windows. He's been encouraged by developers who've said, "This is great! I already have a Windows server. Now I don't have to have a second server for my PHP apps."
Serack is completely open to help and suggestions from the PHP community; he's hoping people (why yes, that means you) will have a voice in prioritizing upcoming PHP on Windows tasks, especially from those who can help tracking down issues and help optimizing. (Just send him an e-mail message, if you don't find him in one of the PHP communities you frequent or in the discussion lists on php.net). "When there's something wrong let's fix it," he says.
"We've given people a choice," Serack says. "Now they can do PHP on Windows, and expect it to run appropriately."
Follow ITworld on Twitter: @IT_world