简体   繁体   English

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

[英]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? 如何运行位于远程服务器上dll文件中的COM对象?

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

How can I run COM object from remote server ? 如何从远程服务器运行COM对象? Exactly like you run local objects. 就像您运行本地对象一样。 You only have to pass the IP of the remote machine as second parameter to the COM constructor. 您只需要将远程计算机的IP作为第二个参数传递给COM构造函数。

Make sure that you have set com.allow_dcom=TRUE in your php.ini. 确保已在php.ini中设置com.allow_dcom = TRUE。

I have com.allow_dcom enabled in my php.ini and according to phpinfo(); 我在php.ini中启用了com.allow_dcom,并根据phpinfo()启用了com.allow_dcom; I do in fact have COM support, DCOM support, and .NET support enabled. 实际上,我确实启用了COM支持,DCOM支持和.NET支持。 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. DLL文件(pcmsrv32.dll)位于远程服务器上的C:\\ Windows中。 I need to access the object method CalcDistance() which is stored in that file. 我需要访问存储在该文件中的对象方法CalcDistance()。

I have tried to pass the file location and the IP to the COM class: 我试图将文件位置和IP传递给COM类:

$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: 我还尝试使用PC * Miler | Connect用户指南中提供的ProgID,并将其用于我的代码中:

$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: 我最终获得了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 
?>

EDIT I am now being told that PC*Miler only offers their COM objects locally. 编辑现在我被告知PC * Miler仅在本地提供其COM对象。 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. 我们将PC * Miler的版本30安装到我的PHP代码所在的同一台服务器上,然后尝试进行安装。

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: 更新我们在同一服务器上安装了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;

Output of $properDist was 288 miles - which I verified was correct with Google Maps. $properDist输出为288英里-我验证了Google Maps是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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