如何 运行 PHP 远程服务器上的 COM 对象

How to run COM objects on a remote server in PHP

如何 运行 位于远程服务器上的 dll 文件中的 COM 对象?

根据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.

根据 phpinfo(),我在 php.ini 中启用了 com.allow_dcom;事实上,我确实启用了 COM 支持、DCOM 支持和 .NET 支持。我很难找到如何调用远程对象的示例。

DLL 文件 (pcmsrv32.dll) 位于远程服务器上的 C:\Windows 中。 我需要访问存储在该文件中的对象方法 CalcDistance()。

我已经尝试将文件位置和 IP 传递给 COM class:

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

但这不起作用。我收到此错误:

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

我还尝试使用 PC*Miler|Connect 用户指南中给出的 ProgID,并在我的代码中使用了它:

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

但是这给了我这个错误:

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

我做错了什么?

我最终联系了 PC*Miler 支持人员,他们给了我一个示例代码,用于进行基本调用,可以 运行 作为 CLI 脚本:

<?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 
?>

编辑 我现在被告知 PC*Miler 只在本地提供他们的 COM 对象。因此,除非我将它安装在我正在开发的同一台服务器上,否则这是行不通的。我们正在将 PC*Miler 的 30 版安装到我的 PHP 代码所在的同一台服务器上,然后尝试这样做。

更新 我们在同一台服务器上安装了 v.30 的 PC*Miler,以及修复 php 错误的补丁,我能够成功 运行 以下代码:

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;

$properDist 的输出是 288 英里 - 我用 Google 地图验证了它是正确的。