简体   繁体   中英

PHP COM works over CLI but not through HTTP

I am trying to connect to a gateway of SnelStart, accounting software from the Netherlands. To do so, I have registered the gateway DLL called SnelStartGateWay.dll by calling regsvr32 SnelStartGateWay.dll from a command prompt with administrator rights.

Here's a simple piece of my PHP code:

$gw = new COM('SnelStartGateWay.clsGWaySnelStart');
$gw->mtdGWayAdmiOpenen('D:\SnelStart', 'SnelStart Voorbeeldbedrijf');

When I run this code from a command prompt with the PHP that comes with my XAMPP installation on the same PC as where I have installed and registered SnelStart and the gateway, no error occurs and I can even continue with creating a new customer and order through the gateway.

However, when I run the exact same PHP file through HTTP Apache from the same XAMPP installation (which is what I want to be able to achieve eventually), I get the following error:

<br />
<b>Fatal error</b>:  Uncaught exception 'com_exception' with message '&lt;b&gt;Source:&lt;/b&gt; SnelStart
mtdGWayAdmiOpenen&lt;br/&gt;&lt;b&gt;Description:&lt;/b&gt; U kunt alleen gebruik maken van SnelStart Gateway als deze module geregistreerd is. Het registreren en gebruiken van SnelStart Gateway is gratis. Vraag een gratis registratie aan via info@snelstart.nl (vergeet niet uw naam en adresgegevens te vermelden).' in D:\xampp\htdocs\snelstart.php:7
Stack trace:
#0 D:\xampp\htdocs\snelstart.php(7): com-&gt;mtdGWayAdmiOpenen('D:\SnelStart', 'SnelStart Voorb...')
#1 {main}
  thrown in <b>D:\xampp\htdocs\snelstart.php</b> on line <b>7</b><br />

Though a part of the error message is in Dutch, it reads that you need to register the gateway and enable it in the software. But the funny thing is, it runs through the CLI without a hassle.

Could it be possible that I need to change the way PHP runs through HTTP is the same as with the rights it has when it runs through the CLI? Could this be an issue with local rights?

I have also already tried disabling my firewall and anti-virus, but so far without any luck.

Thanks in advance.

I am now running the Windows Apache service as the local user account, which also has access to the software package of SnelStart. How to find out which user account to use, I manually started Apache with the batch script in its /bin folder. Then with Task manager I checked which account this belongs to, and confirmed that the script did run at that moment. As it did, I changed the service to run with that local account, and do the usual stuff such as auto starting the service. Now it all runs well!

You have to find out what way the registration info is fetched by their code. Probably the PHP CLI security settings (in php.ini) are more relaxed than the Apache PHP security settings (typically in another php.ini, combined with whatever php_admin_values you find in the Apache config).

It could be an open_basedir restriction, an include path that's different, not allowing url wrappers etc, or just the fact that Apache runs your code as another user, having restricted access compared to the account you are using to run this in CLI.

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