Calling Excel from PHP 5 through COM fails on Windows 7 when Apache started through Task Planner

Posted by Stefan Pantke on Server Fault See other posts from Server Fault or by Stefan Pantke
Published on 2011-11-27T14:32:14Z Indexed on 2011/11/27 17:55 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

I currently write an application, which controls Excel through COM: The app creates a COM-based Excel instance, opens some XLS files and reads their contents.

Scenario I

On Windows 7, I start Apache and mySQL using xmapp-control with system administrator rights. All works as expected. The PHP-based controller script interacts with Excel as expected.

Scenario II

A problem appears, if I start Apache and mySQL as 'background jobs'. Here is how:

  • I created two jobs using Windows 7 Task Planner. One runs apache_start.bat, the other runs mysql_start.bat.
  • Both tasks run as SYSTEM with elevated privileges when Windows 7 boots.

Apache and mySQL work as expected. Specifically, Apache serves HTTP request from clients and PHP is able to talk to mySQL.

When I call the PHP controller, which calls and interacts with Excel using COM, I do receive an error.

The error seems to come from Excel [not COM itself] and reads like this:

  • Excel can't read the XLS-file
  • Excel failed to save the file due to an ill-name worksheet

Interestingly, during the first run of the PHP-based controller script, it takes a few seconds to render the error message. Each subsequent run immediately renders the error message.

Windows system logs didn't show a single problem report entry.

Note, that the PHP program and the Apache instance didn't change - except the way Apache was started.

At least the PHP controller script is perfectly able to read the file-system, since it provides the pathes to the XLS-file through scandir() of a certain directory.

Concurrency issues can't be the cause of the problem. A single instance of the specific PHP controller interacts with Excel.

Question

Could someone provide details, why this happens?

© Server Fault or respective owner

Related posts about apache2

Related posts about php