php-doc-en/faq/com.xml

287 lines
8 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="faq.com" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>PHP and COM</title>
<titleabbrev>PHP and COM</titleabbrev>
<para>
PHP can be used to access COM and DCOM objects on Win32 platforms.
</para>
<qandaset>
<qandaentry xml:id="faq.com.q1">
<question>
<para>
I have built a DLL to calculate something. Is there any way to run this DLL under PHP ?
</para>
</question>
<answer>
<para>
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.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q2">
<question>
<para>
What does 'Unsupported variant type: xxxx (0xxxxx)' mean ?
</para>
</question>
<answer>
<para>
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.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q3">
<question>
<para>
Is it possible manipulate visual objects in PHP ?
</para>
</question>
<answer>
<para>
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.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q4">
<question>
<para>
Can I store a COM object in a session ?
</para>
</question>
<answer>
<para>
No, you can't. COM instances are treated as resources and therefore they are only available in a single script's context.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q5">
<question>
<para>
How can I trap COM errors?
</para>
</question>
<answer>
<para>
The COM extension throws <literal>com_exception</literal>
exceptions, which you can catch and then inspect the <literal>code</literal>
member to determine what to do next.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q6">
<question>
<para>
Can I generate DLL files from PHP scripts like I can in Perl ?
</para>
</question>
<answer>
<para>
No, unfortunately there is no such tool available for PHP.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q7">
<question>
<para>
What does 'Unable to obtain IDispatch interface for CLSID {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' mean ?
</para>
</question>
<answer>
<para>
This error can have multiple reasons:
<itemizedlist>
<listitem>
<simpara>
the CLSID is wrong
</simpara>
</listitem>
<listitem>
<simpara>
the requested DLL is missing
</simpara>
</listitem>
<listitem>
<simpara>
the requested component doesn't implement the IDispatch interface
</simpara>
</listitem>
</itemizedlist>
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q8">
<question>
<para>
How can I run COM object from remote server ?
</para>
</question>
<answer>
<para>
Exactly like you run local objects. You only have to pass the IP of the remote machine as second parameter to
the COM constructor.
</para>
<para>
Make sure that you have set
<link linkend="ini.com.allow-dcom">com.allow_dcom</link><literal>=</literal>&true;
in your &php.ini;.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q9">
<question>
<para>
I get 'DCOM is disabled in C:\path...\scriptname.php on line 6', what can I do ?
</para>
</question>
<answer>
<para>
Edit your &php.ini; and set
<link linkend="ini.com.allow-dcom">com.allow_dcom</link><literal>=</literal>&true;.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q10">
<question>
<para>
Is it possible to load/manipulate an ActiveX object in a page with PHP ?
</para>
</question>
<answer>
<para>
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.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q11">
<question>
<para>
Is it possible to get a running instance of a component ?
</para>
</question>
<answer>
<para>
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:
</para>
<programlisting role="php">
<![CDATA[
<?php
$word = new COM("C:\docs\word.doc");
?>
]]>
</programlisting>
<para>
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.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q12">
<question>
<para>
Is there a way to handle an event sent from COM object ?
</para>
</question>
<answer>
<para>
You can define an event sink and bind it using
<function>com_event_sink</function>. You can use
<function>com_print_typeinfo</function> to have PHP generate a skeleton
for the event sink class.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q13">
<question>
<para>
I'm having problems when trying to invoke a method of a COM object
which exposes more than one interface. What can I do ?
</para>
</question>
<answer>
<para>
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 <link xlink:href="mailto:&email.harald;">me</link> know :)
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q14">
<question>
<para>
So PHP works with COM, how about COM+ ?
</para>
</question>
<answer>
<para>
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.
</para>
</answer>
</qandaentry>
<qandaentry xml:id="faq.com.q15">
<question>
<para>
If PHP can manipulate COM objects, can we imagine to use
MTS to manage components resources, in conjunction with PHP ?
</para>
</question>
<answer>
<para>
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.
</para>
</answer>
</qandaentry>
</qandaset>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->