2017-03-08 51 views
0

如何運行位於遠程服務器上的dll文件中的COM對象?如何在PHP中的遠程服務器上運行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.

我已經com.allow_dcom在我的php.ini根據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 

我已使用ProgID的用戶指南PC *米勒在給定的也試過|連接和使用,在我的代碼:

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

然而,讓我這個錯誤:

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

我在做什麼錯?

+0

可能的[如何使用PHP加載存儲在遠程服務器上的DLL]的重複(http://stackoverflow.com/questions/42660347/how-to-load-dll-stored-on-remote-server-in-php ) – yivi

+0

我已經刪除了我的其他問題,因爲我嘗試了一些不同的東西來解決我的問題。我也可能最終刪除這個。 –

回答

0

我最終得到與PC *米勒支持觸摸,他們給了我一個示例代碼使得可以運行的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代碼所在的同一臺服務器上,然後嘗試使用它。

UPDATE 我們不得不安裝在同一臺服務器,以及用於固定一個PHP的bug補丁的PC *米勒的V.30,我能夠成功運行下面的代碼:

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地圖驗證是正確的。

相關問題