PHP: PHP and COM - Manual
PHP  
downloads | documentation | faq | getting help | | php.net sites | links 
search for in the  
previousPHP and HTMLPHP and other languagesnext
Last updated: Wed, 24 Jul 2002
view this page in Printer friendly version | English | Brazilian Portuguese | Czech | Dutch | Finnish | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

�� 53. PHP and COM

PHP can be used to access COM and DCOM objects on Win32 platforms.

1. I have built a DLL to calculate something. Is there any way to run this DLL under PHP ?
2. What does 'Unsupported variant type: xxxx (0xxxxx)' mean ?
3. Is it possible manipulate visual objects in PHP ?
4. Can I store a COM object in a session ?
5. How can I trap COM errors ?
6. Can I generate DLL files from PHP scripts like i can in Perl ?
7. What does 'Unable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' mean ?
8. How can I run COM object from remote server ?
9. I get 'DCOM is disabled in C:\path...\scriptname.php on line 6', what can I do ?
10. Is it possible to load/manipulate an ActiveX object in a page with PHP ?
11. Is it possible to get a running instance of a component ?
12. Is there a way to handle an event sent from COM object ?
13. I'm having problems when trying to invoke a method of a COM object which exposes more than one interface. What can I do ?
14. So PHP works with COM, how about COM+ ?
15. If PHP can manipulate COM objects, can we imagine to use MTS to manage components resources, in conjunction with PHP ?

1. I have built a DLL to calculate something. Is there any way to run this DLL under PHP ?

If this is a simple DLL there is no way yet to run it from PHP. If the DLL contains a COM server you may be able to access it if it implements the IDispatch interface.

2. What does 'Unsupported variant type: xxxx (0xxxxx)' mean ?

There are dozens of VARIANT types and combinations of them. Most of them are already supported but a few still have to be implemented. Arrays are not completely supported. Only single dimensional indexed only arrays can be passed between PHP and COM. If you find other types that aren't supported, please report them as a bug (if not already reported) and provide as much information as available.

3. Is it possible manipulate visual objects in PHP ?

Generally it is, but as PHP is mostly used as a web scripting language it runs in the web servers context, thus visual objects will never appear on the servers desktop. If you use PHP for application scripting e.g. in conjunction with PHP-GTK there is no limitation in accessing and manipulating visual objects through COM.

4. Can I store a COM object in a session ?

No, you can't. COM instances are treated as resources and therefore they are only available in a single script's context.

5. How can I trap COM errors ?

Currently it's not possible to trap COM errors beside the ways provided by PHP itself (@, track_errors, ..), but we are thinking of a way to implement this.

6. Can I generate DLL files from PHP scripts like i can in Perl ?

No, unfortunately there is no such tool available for PHP.

7. What does 'Unable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' mean ?

This error can have multiple reasons:

  • the CLSID is wrong

  • the requested DLL is missing

  • the requested component doesn't implement the IDispatch interface

8. How can I run COM object from remote server ?

Exactly like you run local objects. You only have to pass the IP of the remote machine as second parameter to the COM constructor.

Make sure that you have set com.allow_dcom=true in your php.ini.

9. I get 'DCOM is disabled in C:\path...\scriptname.php on line 6', what can I do ?

Edit your php.ini and set com.allow_dcom=true.

10. Is it possible to load/manipulate an ActiveX object in a page with PHP ?

This has nothing to do with PHP. ActiveX objects are loaded on client side if they are requested by the HTML document. There is no relation to the PHP script and therefore there is no direct server side interaction possible.

11. Is it possible to get a running instance of a component ?

This is possible with the help of monikers. If you want to get multiple references to the same word instance you can create that instance like shown:

$word = new COM("C:\docs\word.doc");

This will create a new instance if there is no running instance available or it will return a handle to the running instance, if available.

12. Is there a way to handle an event sent from COM object ?

Not yet.

13. I'm having problems when trying to invoke a method of a COM object which exposes more than one interface. What can I do ?

The answer is as simple as unsatisfying. I don't know exactly but i think you can do nothing. If someone has specific information about this, please let know :)

14. So PHP works with COM, how about COM+ ?

COM+ extends COM by a framework for managing components through MTS and MSMQ but there is nothing special that PHP has to support to use such components.

15. If PHP can manipulate COM objects, can we imagine to use MTS to manage components resources, in conjunction with PHP ?

PHP itself doesn't handle transactions yet. Thus if an error occurs no rollback is initiated. If you use components that support transactions you will have to implement the transaction management yourself.

User Contributed Notes
PHP and COM
add a note about notes

14-Jun-2002 09:32

hello, we have written a class in php which uses com to create and edit a
excel file. but as we have a lot of data to write, this seems to be very
slow. are there some hints, one has to take attention to, to fasten this?
thanks for your help


25-Jun-2002 11:19

Generating a warning using in PHP a COM Object (written in VB).

If a property is defined so (in IDL):

[propputref] void User([in, out] _CUser** rhs);  

Then I do something like this :
$NewUser = UserPool->GetFreeUser();
$NewEntry->User = $NewUser;

I receive the warning :
Warning: Unable to lookup User: Unknown name.

Do I missunderstand something ?


08-Jul-2002 01:57

try the other way (using com_load and load_invoke) -- somehow the class's
interface is not made IDispatchable, so -> won't always (only
sometimes!?) work


10-Jul-2002 01:38

How can i format the resultstring ($text) which comes from a mysql-query?

---- start code -----
$word = new COM("word.application") or die("Can't start
Word!");
$word->Visible = 1;
$word->Documents->Add();
$word->Selection->Font->Name("Verdana");     // doesn't
work prints it in Times
$word->Selection->Font->Bold();                      // doesn't
work :-(
$word->Selection->TypeText($text);
$word->Documents[1]->SaveAs($fullpath);
$word->Quit();
$word = null;
....
---- end code ---

Everything else is working fine

thanx
Achim Grothkopp


10-Jul-2002 01:40

Hallo Zusammen,

kann mir jemand weiterhelfen, wie ich den aus einer mySQL-DB mittels
PHP/COM
eingef�gten Text
($text) eines Worddocs formatieren kann?

Folgender Code funzt nicht (bei Auszeichnen):

---- start code -----
...           //die query und das Variablenf�llen spare ich mir mal ;-)

$word = new COM("word.application") or die("Can't start
Word!");
$word->Visible = 1;
$word->Documents->Add();
$word->Selection->Font->Name("Verdana");     // es
kommt immer nur Times
$word->Selection->Font->Bold();                      // nix fett
:-(
$word->Selection->TypeText($text);
$word->Documents[1]->SaveAs($fullpath);
$word->Quit();
$word->Release();
$word = null;

....
---- end code ---

ansonsten klappt alles gut.
Merci im voraus!

Gruss
Achim Grothkopp


15-Jul-2002 03:39

Problem: If I use this code
$word = new COM("word.application") or die("Cannot start
word for you"); 
print "Loaded word version ($word->Version)\n";  
$word->visible =1;  
$word->Documents->Add();  

the Word Application is started on the server only but I want it to start
on the client workstation. What do I have to change/alter?

Thanks

Seb

add a note about notes
previousPHP and HTMLPHP and other languagesnext
Last updated: Wed, 24 Jul 2002
show source | credits | stats | mirror sites:  
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by:
Last updated: Sun Jul 28 16:09:02 2002 CEST