Running console program in PHP

0

I wrote a simple PHP code to execute a console program:

<?php
$cmd = escapeshellcmd('progName.exe arg1 arg2 arg3');
exec($cmd);
?>

If I run the command on the console directly on the server, it works. However, when I run the PHP on the browser, it doesn't work. The process progName.exe is running (checked using Task Manager on the server), but it never finishes. This program is supposed to compute some parameters from the arguments and write the result to a binary file, and also produce a .WAV file. Here is the error message I get on the browser:

Error Summary
HTTP Error 500.0 - Internal Server Error
C:\php\php-cgi.exe - The FastCGI process exceeded configured activity timeout

Detailed Error Information
      Module    FastCgiModule
Notification    ExecuteRequestHandler
     Handler    PHP
  Error Code    0x80070102

Then I wrote a simple console program that write a sentence to a text file (writeTxt.exe hello.txt). Using the same PHP script, I ran it on the browser and it works.

I already tried to increase the timeout on the server, but still have the same error. What could cause this problem?

php
webserver
asked on Stack Overflow Sep 20, 2013 by ArthurN • edited Sep 23, 2013 by ArthurN

1 Answer

0

When you execute a program in PHP using the exec function (e.g. exec('dir')), PHP waits until it is ended or you sent it to the background and PHP comes back directly (see documentation, especially the comments).

According to your posted PHP sources ($cmd = escapeshellcmd('progName.exe arg1 arg2 arg3');) the program is not sent to background by PHP - so what stays is that progName.exe...

  1. ...sends itself or a fork to the background (unlikely, but look into the sources of progName.exe)
  2. ...is waiting for input (<-- this is my favorite)
  3. I missed something ;-)

As I said I bet it is the second option. Hope that helped a bit.

answered on Stack Overflow Sep 20, 2013 by Jost

User contributions licensed under CC BY-SA 3.0