如何运行位于远程服务器上的dll文件中的COM对象?
根据php.net(http://php.net/manual/en/faq.com.php#faq.com.q8):
如何从远程服务器运行COM对象?完全像你跑 本地对象。您只需将远程计算机的IP传递为 COM构造函数的第二个参数。
确保在php.ini中设置了com.allow_dcom = TRUE。
我在php.ini中启用了com.allow_dcom并根据phpinfo();事实上我确实启用了COM支持,DCOM支持和.NET支持。我很难找到如何调用远程对象的示例。
DLL文件(pcmsrv32.dll)位于远程服务器上的C:\ Windows中。 我需要访问存储在该文件中的对象方法CalcDistance()。
我试图将文件位置和IP传递给COM类:
$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用户指南中提供的ProgID | Connect并在我的代码中使用它:
$com = new COM("PCMServer.PCMServer.1","10.86.0.21");
然而,这给了我这个错误:
com_exception: Failed to create COM object `PCMServer.PCMServer.1': Invalid syntax
我做错了什么?
答案 0 :(得分:0)
我最终与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 bug的补丁,我能够成功运行以下代码:
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地图验证了这一点。