Page 1 of 1

PHP Script runs on CLI but not through web browser

Posted: Mon Oct 12, 2009 2:20 pm
by ndcisiv
I am running into an issue that I just can't seem to find the answer to. I have a Windows Server 2008 box that is running Apache 2.2.14, PHP 5.2.11, and MySQL 5.1.39. My problem is I am trying to call a VBScript that interracts with a database on another machine but I can't seem to get it to actually run the script.

Watching Process Explorer I can clearly see that httpd.exe spawns php-cgi.exe which spawns wscript.exe so it appears that the actual call is working. However, after a few seconds the php-cgi.exe process closes and the wscript.exe process breaks out into its own process (no parent anymore) and never runs the code or closes. I actually have to end task for it to go away. When I run the script through PHP Command Line, it works perfectly as expected.

This happens both with the vbscript being on the local machine, and on a UNC path of another machine. I stripped down the code to the most simple form I could, and even tried putting nothing more than a message dialog in the VBScript, and still I run into this error. Does anyone know why this might be happening? I don't see any errors in the logs, or through the browser when the page loads.

This exact same setup was working on a Windows 2000 Server machine so I'm not sure if this is something unique to 2008 or just a overlooked setting somewhere.

Re: PHP Script runs on CLI but not through web browser

Posted: Mon Oct 12, 2009 2:31 pm
by requinix
CLI and CGI are very nearly the same. What's your code?

Re: PHP Script runs on CLI but not through web browser

Posted: Mon Oct 12, 2009 2:37 pm
by ndcisiv
Even with extremely simple code it happens, such as:

<?php

$oShell = new COM("WScript.Shell");
$oShell->Run("C:\test\test.vbs");

?>

Where test.vbs contains:
WScript.echo "Hello!"

I may be oversimplifying this, but I thought if it happens with this, there is something wrong. Any ideas?

Re: PHP Script runs on CLI but not through web browser

Posted: Wed Oct 14, 2009 12:18 pm
by ndcisiv
After searching high and low, I found that running Apache as a service on Vista/2008 is different than say, on XP. Apparently the Apache service is not allowed to interact with the desktop, even if you select "Allow service to interact with desktop". I switched Apache to run just as a program instead and the script worked! I guess calling anything that displays a GUI requires the ability to interact with the desktop, so if anyone runs into this problem, maybe this solution will work?