As an old fashioned programmer I grew up with debugging methods like post-mortem traces and trace statements.
Today however we have and are used to GUI’s for debugging and can single step code or even re-compile code and retry the operation. This is all nice in environments where applications can be frozen. If not, like web pages and applications depending on real-time communication with devices the single stepping alone ruins the applications workings and thus the debugging process.
Here old fashioned trace message and a viewer for them come in handy again. Normally on Microsoft Windows one uses the OutputDebugString() API. For PHP this API call was missing so I implemented a simple PHP extension that wrapped the API in two ways. One is just the call and the other way is as member function of an object.
Big advantage of the OutputDebugString() API is that if there is no viewer active, the output is just ignored and vanishes into thin air, leaving no traces like massive log files. Also good to know is that it’s impossible to ruin http headers etc as the output is redirected to something else then the web browser.
The result is a very easy to use extension that can be left in the code for as long as one want/needs.
The following snippet test of the module is indeed loaded properly by the PHP interpreter:
This snippet uses the php_log class:
The cleardebugwindow() method send a special message to DbgView clearing the display. Outputdebugstring() takes two parameters, the message and a severity string. This last parameter is handy for grouping the messages or be able to search on certain types. It is not necessary to use the built-in types like info, warning or error, any tag is allowed.
The following code is not using classes: