Podcast on Running PHP on Windows

Peter Laudati & Dmitry Lyalin host the edu-training Connected Show developer podcast on cloud computing and interoperability. I met Peter in Chicago during Tek-X and we along with Don and Wade recorded a podcast on evolution of PHP on the Windows Platform. We talked about the improvements made to Windows in order to support PHP, including: Fast CGI, WinCache, PHP 5.3, the Web PI, and the SQL Server driver for PHP. Check out episode #31, “PHP On Windows” on Connected Show. Interview starts at 24:31.

CLICK HERE TO LISTEN!

If you like what you hear, check out previous episodes of the Connected Show at www.connectedshow.com.  You can subscribe on iTunes or Zune.  Peter and Dmitry publish new episodes approximately every two weeks!

Thanks,
Kanwal

Impact of name resolution on mysql_connect perfomance

I spend lot of time profiling popular PHP applications finding where exactly processing time is spent during PHP execution. Few months ago, one thing which caught my attention was performance of mysql_connect API. On my windows test bench, xdebug output showed that one call to mysql_connect was taking 0.31 seconds which is huge. While playing with the API, I noticed that when IP address of the MySQL machine is used instead of the hostname, performance of mysql_connect API is much better. Below is a simple script I ran to test this.
 
1. <?php 
2.     $hostname = "hostname";
3.     $ipaddress = "1.1.1.1";
4. 
5.     $starttime = microtime(true);
6.     for($cnt = 0; $cnt < 10; $cnt++) {
7.         $connection = mysql_connect($hostname, 'username', 'password');
8.         mysql_close($connection);
9.     }
10.    $endtime = microtime(true);
11.    echo ($endtime - $starttime . "\n");
12.
13.    $starttime = microtime(true);
14.    for($cnt = 0; $cnt < 10; $cnt++) {
15.        $connection = mysql_connect($ipaddress, 'username', 'password');
16.        mysql_close($connection);
17.    }
18.
19.    $endtime = microtime(true);
20.    echo ($endtime - $starttime);
21. ?>
Below is the output I got when I ran the above script on my test bench.

3.14003 seconds (time taken for 10 mysql_connect calls when hostname was used)
0.01396 seconds (time taken for 10 mysql_connect calls when IP address was used)

As you can see in the results, hostname resolution slows down mysql_connect significantly and the performance hit seems to happen on each mysql_connect call. This slowdown only happens when connection is made to a remote machine. When MySQL and web server both ran on the same machine, there was no performance difference between hostname and ipaddress case. So if you are running MySQL on a remote machine, use IP address in the mysql_connect call. Alternatively you can add an entry in %windir%\system32\drivers\etc\hosts file to tell your system IP address of MySQL machine. System will find this entry in the hosts file and pick the IP address of MySQL box directly without going through more expensive name resolution. Change hosts file only if you have a static IP address. Name resolution performance will depend on your DNS/WINS configuration and on your network topology. So you should run the script above to find out performance impact of hostname resolution before making any changes.

Hope this helps.
Kanwal

Work items collected from Tek-X

Last week I was in Chicago in the company of very passionate and smart PHP programmers at Tek-X. I got to meet some well-known members of PHP community and also fellow Microsoft employees who have been working on improving PHP experience of Windows. I would admit that meeting people was the best part of Tek-X for me. Sessions were great too and I learnt a great deal from them. I returned to Seattle more knowledgeable and passionate for PHP then ever. One of the things I wanted to get from Tek-X was a list of problems PHP users face on Windows so that we can work on solving them. Below is the list of work items I collected during informal discussions, questions during my talk and from other sessions.
 
1.       PHP 5.3 in WebPI
Today, Web Platform Installer (WebPI) only offers latest version of PHP 5.2. Folks want us to offer PHP 5.3 through WebPI. We receivedthis request during web developer summit and work for this is already in progress.
 
2.       PECL extensions in WebPI
There are few PECL extensions which are very popular (e.g. XDebug, uploadprogress) and people want us make them available in WebPI.
 
3.       WebPI to download PHP from windows.php.net
During my WebPI demo, Derick Rethans pointed out that we are downloading PHP from http://sourceforge and not http://windows.php.net. We used to install PHP from windows.php.net but moved recently to sourceforge when windows.php.net went down for maintenance. We will move back to windows.php.net once it has mirrors set.
 
4.       SQL driver for PHP extension on PECL
PHP community is very happy with the fact that WinCache source code is in PECL repository and documentation is exclusively available on php.net. They want SQL driver for PHP extension to move from codeplex to PECL. Even better will be moving related documentation from http://www.microsoft.com to http://www.php.net as well.
 
5.       PHP frameworks in WebPI
During my talk, people asked if there are any plans to add popular PHP frameworks like CakePHP and Zend Framework in WebPI. If a PHP application code already has framework code included, WebPI will just copy that as part of application install. Right now there are no plans to offer standalone PHP frameworks from WebPI. I will be discussing with the product team and see if this makes sense for us.
 
6.       Simplify setting up of PHP build environment on Windows
Many at Tek-X made fun of the fact that compiling PHP on Windows is incredibly hard. I have published a script (winbuild.bat) which makes this very easy. I will continue to produce documentation/scripts related to this unless building PHP on Windows is seen as a simple task.
 
7.       CHM file for PHP documentation script
Gennady told me that script which pulls in php.net documentation and creates a CHM file is broken and need some fixes. He loves access to php documentation even when offline and want the script to work. I will be looking at it and try to fix it.
 
8.       Pre-built PECL binaries for Windows
http://pecl4win.php.net has been down for ages. Many showed frustration with the fact that pre-built PECL binaries for Windows are hard to get. Pierre has few extensions built regularly and has them available for download here. Getting binary for an extension which is not available here is as easy as sending Pierre an email. If you want to build the PECL extension yourself, you can follow the instructions here. We still need to look into pecl4win.php.net or its replacement plans.
 
9.       Getting operating system information from PHP is hard
Elizabeth Marie Smith, in her awesome Cross Platform PHP talk, mentioned that getting system information on Windows is hard. I will be following up on this and make fixes to PHP as needed.
 
10.   Debugging dependency check errors is very hard
Elizabeth Marie Smith mentioned this in her talk. I will look into this and see what can be done.
 
I will be following up on each of these and hopefully will close on most of these requests before Tek-2011J. If this list doesn’t capture something you need for better php on Windows experience, please leave a comment and I will add it to this list.
 
Thanks,
Kanwal

Using IIS configuration tools to manage HWC configuration

I have seen many people built some innovative solutions on top of hostable web core (HWC) functionality which was added in IIS7. One of the questions which HWC users frequently ask is how to make IIS configuration tools (like appcmd, UI etc.) work against configuration file which their HWC instance is using. So far they have been either doing manual modifications to HWC configuration file or making changes to IIS configuration and then porting over to HWC configuration. There is an easier way to do this but caveat is that this requires your HWC configuration file name to be applicationHost.config. If that is the case, you can use IIS shared configuration feature to setup a redirection to your HWC configuration file. Below are the steps to get this working.
 
-          Open %windir%\system32\inetsrv\config\redirection.config.
-          Change <configurationRedirection /> to <configurationRedirection enabled=”true” path=”c:\HWCInstance\” />
-          Save and exit.
 
With this change, configuration system will map MACHINE/CONFIG/APPHOST to c:\HWCInstance\applicationHost.config and assume this as the main configuration file containing applicationPools and sites information. Now appcmd, UI etc. will work against HWC configuration file. Please note that setting up this redirection will affect your main instance of IIS as well. So if you are using IIS and HWC in parallel, this won’t be a safe thing to do. But if you are not using IIS main instance and only running your own HWC instance, this can be used to make IIS configuration tools work against your HWC configuration.
 
Hope this helps.
Kanwal

WordPress widget to show WinCache statistics

Ruslan (http://ruslany.net), who is Program Manager for WinCache project, has been showing WinCache statistics on the right sidebar of his website for quite some time. Few weeks ago I decided to do the same but instead of editing theme source code and add the information there, I decided to write a standalone wordpress widget. Two days ago I finally wrote the widget which is aptly called wincache-stats. It shows statistics in a table format. First column of the table show cache type and number of entries in cache, second column show hit count and hit ratio and third column show miss count and miss ratio. It can be see in action on http://www.ksingla.net. I submitted the widget to wordpress.org yesterday and it has been approved. So this is available for download from wordpress.org here. If you want to look at the source code, you can see it here. Below is a snapshot of the wincache-stats widget.
 
 
You can choose what statistics to show in the wordpress admin interface. Picture below shows admin interface of wincache-stats widget.
 
 
I hope some of the WinCache users use this widget on their website to see WinCache usage and in the process, help us spread the word about WinCache. If you want to report a bug or request a feature, please leave a comment to this blog.
 
Thanks,
Kanwal