PHP handles COM objects as native PHP objects, meaning that you can read and write variables, and also call functions, just like you would on any other object. The COM object class is simple "COM", and you need to pass it the name of COM component to create as the parameter to its constructor.
To find out the names of the COM components you have installed (you almost certainly have hundreds), click Start, then Run, then enter "regedit" and click OK. From the three on the left, open up HKEY_CLASSES_ROOT, and you will see a long list of file extensions, probably ending around ".zip". After that, you will see a big long list of the names of COM components - just pick one from there, and you are all set.
Note that COM scripts should generally be run from the command line. Running them through a web server is possible, but COM objects that interact with the user on the server need to have special permissions granted to them. This can usually be accomplished using the Services administrative tool, but this may be different on your version of Windows.
It is important to note that starting a complicated COM object for the first time will be quite slow, but a lot of the information is cached by Windows for several minutes after the object is freed, so subsequent start ups will be much faster. If you find a script is executing slowly, try it out a few times to see whether it is just the initial start up time that is slow.
Want to learn PHP 7?
Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!
If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!
Next chapter: Basic COM >>
Previous chapter: Getting started with COM
Home: Table of Contents
Copyright ©2015 Paul Hudson. Follow me: @twostraws.