14.1.1 Instantiating an objectThis is NOT the latest copy of this book; click here for the latest version.
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.
Just below is a screenshot of how to enable Apache to launch visible desktop applications that can be interacted with:

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 see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|