Debugging WINCACHE on Windows using Visual Studio - Basic

Posted: Dec 09, 2009  1 comments  

Average Rating

Tags
PHP
PHP Wincahe
WINCACHE Debugging

Share this Post

In this post I am going to talk about basic tools you will need as well as basic steps which will enable you to start debugging WINCACHE. I will talk about a way to debug WINCACHE running in both PHP CLI as well as CGI version. I am planning to write a series of blog post which will be helpful in debugging WINCACHE. This is just the beginning. So please be patient and forgive me if some of the posts sound for novice user. All my post will assume that you are debugging PHP CGI running under IIS using FastCGI. This means using the non thread safe version of PHP/WINCACHE and IIS running PHP files successfully. I believe the same can be applied to thread safe version of WINCACHE/PHP running under Apache but I do not guarantee that.

There are some basic things you will need to start with:

Once you have PHP and WINCACHE build, you will need to:

  • If you have done a non thread safe build the binaries could be found at the folder named ‘Debug’. This folder will be at the same level to the folder which contains PHP sources.
  • You will see executable named php.exe in the ‘Debug’ folder.
  • In the Debug folder create a file named php.ini which contains the following:

extension_dir=C:\PHP_5_2_src\Debug <Replace it with your path to ‘Debug’ folder>
extension=php_wincache.dll
wincache.enablecli=1

  • Invoke Visual Studio 2008 command prompt. This will be present in the Visual Studio tools folder. or just hit Windows button + R and type ‘Visual Studio Command Prompt’.
  • Change directory to Debug folder in the Visual Studio Command Prompt.
  • From the Visual Studio command prompt say ‘devenv.exe php.exe’ and hit Enter.
  • In the solution explorer, right click on the project name (should be ‘php’) and click on ‘Properties’. In the ‘Arguments’ section type
    • -c C:\PHP_5_2_src\Debug <path to a valid PHP file>
    • C:\PHP_5_2_src\Debug is the folder where PHP.INI we created just now is present. Change it accordingly.
  • Visual Studio has already created a solution file. Save it. It’s good idea to save it at default location which will be the ‘Debug’ folder.
  • Now set breakpoint in WINCACHE code and hit F5. And you are all set.
  • If you want to edit the sources, edit it in VS, build it again as outlined and the solution file will pick up the latest changes.

One thing to note here. Using above procedure you can as well debug PHP sources. So it is not limited to WINCACHE.

Debugging WINCACHE using PHP CGI

This is also an important scenario. In order to debug WINCACHE using CGI, do the following:

  • Install PHP any version (5.2/5.3) to run under IIS using FastCGI.
  • Do a wincache build as outlined above for appropriate version. This means if you have installed PHP 5.3, WINCACHE should be build using 5.3 sources. The same applies to PHP 5.2.
  • Do a release build this time (no –enable-debug flag with configure.js) but do use –enable-debug-pack flag as this will generate the PDB.
  • Copy the php_wincache.dll and php_wincache.pdb to the directory where your PHP extensions are present.
  • Edit PHP.INI to include WINCACHE extension.
  • Run the PHP program using PHP CGI in a browser.
  • Open ‘devenv’ in administrator mode. Run Visual Studio Command Prompt as administrator and type devenv.exe, or from the start menu find Visual Studio, right click on it and click run as administrator.
  • Go to Tools—>Options in the menu. Click on Debugging—>Symbols in the Options dialog. Add path to php_wincache.pdb here. Save.
  • In Visual Studio, click on Tools—>Attach To Process.
  • Click the checkbox which says ‘Show processes from all users’. This will ensure that php-cgi.exe is visible in the process list.
  • Select php-cgi.exe and select ‘OK’ button.
  • Now set breakpoint and hit refresh in the browser.
  • You are all set.

If there are multiple PHP CGI process running you may need to do the above step using different instances of Visual Studio (VS) and attach it to different PHP CGI process.

You can also use Windows Debugging Tools at  http://www.microsoft.com/whdc/devtools/debugging/installx86.Mspx (the link points to 32 bit debugging tools) to debug WINCACHE but I love Visual Studio because of the UI and rich set of easy to use features it provides. Again this is my personal opinion and the higher SKU of VS is just too good for debugging. Well I love it.

We are really looking forward to people who can contribute to WINCACHE. So do try this and let me know how helpful is this. If you have further questions, feel free to ask me.

So now you know basics of  how to debug WINCACHE with PHP running in both CLI as well as CGI mode. Hope this helps in debugging WINCACHE. I will talk more in later posts but till then ‘Good Bye’ and ‘Shabba Khair’.

Thanks,

Don.

Next Post