简体   繁体   中英

How to run COM objects on a remote server in PHP

How can I run a COM object that is located in a dll file on a remote server?

According to php.net ( http://php.net/manual/en/faq.com.php#faq.com.q8 ):

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.

I have com.allow_dcom enabled in my php.ini and according to phpinfo(); I do in fact have COM support, DCOM support, and .NET support enabled. I am having a hard time finding examples of how to call the remote objects.

The DLL file (pcmsrv32.dll) is located in C:\\Windows on a remote server. I need to access the object method CalcDistance() which is stored in that file.

I have tried to pass the file location and the IP to the COM class:

$obj = new COM("C:\Windows\PCMSRV32.DLL","10.86.0.21");

But that does not work. I get this error:

Fatal error: Uncaught com_exception: Failed to create COM object `C:\Windows\PCMSRV32.DLL': Moniker cannot open file in C:\Users\...\index.php:33

I have also tried using the ProgID given in the User Guide for PC*Miler|Connect and used that in my code:

$com = new COM("PCMServer.PCMServer.1","10.86.0.21");

However that gives me this error:

com_exception: Failed to create COM object `PCMServer.PCMServer.1': Invalid syntax 

What am I doing wrong?

I ended up getting in touch with PC*Miler Support, and they gave me a sample code for making a basic call that can be run as a CLI script:

<?php 
  // Create COM Object 
  $pcms = new COM("PCMServer.PCMServer"); 
  // Calculate 
  $dist = $pcms->CalcDistance("12345","23456"); 
  // Returned distance is a INT that needs to be divided by 10 (or the number of decimal places specified in the PCMSServe.ini file located in C:\Windows 
  $properDist = ($dist/10); 

  echo $properDist 
?>

EDIT I am now being told that PC*Miler only offers their COM objects locally. So unless I have it installed on the same server that I am developing on, this will not work. We are installing version 30 of PC*Miler to the same server where my PHP code resides and trying that instead.

UPDATE We had v.30 of PC*Miler installed on the same server, as well as the patch that fixes a php bug, and I was able to successfully run the following code:

try {
    $pcms = new COM("PCMServer.PCMServer");
}
catch (com_exception $e) {
    print $e . "\n";
}
// Calculate
$dist = $pcms->CalcDistance("Goodyear, AZ","Las Vegas, NV");
$properDist = ($dist/10);
echo $properDist;

Output of $properDist was 288 miles - which I verified was correct with Google Maps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM