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?

ArthurN
  • 169
  • 4
  • 14
  • What happens if you run `writeTxt.exe hello.txt` (and not `progName.exe `) via PHP from the console? – Jost Sep 20 '13 at 11:03
  • How to run it via PHP on the console? – ArthurN Sep 20 '13 at 11:04
  • Looks like problem with the return, it just executes progName and does not return, what does progName looks like? – Wiggler Jtag Sep 20 '13 at 11:04
  • Is the console application one you've developed? Have you tried attaching a debugger? – Rowland Shaw Sep 20 '13 at 11:05
  • @Wiggler Jtag: However, if I run `progName.exe` directly on the console (on the server), it works. `progName.exe` reads from 3 arguments and produces 2 files: a binary file and a .WAV file. – ArthurN Sep 20 '13 at 11:06
  • @Rowland Shaw: yes, I developed the console program. Is it possible to debug a console program run via PHP? – ArthurN Sep 20 '13 at 11:10
  • Depending on the toolchain you used to develop the console app, most support attaching to a running process, pausing it to find out where it is in code. Worst case scenario would be to use something like [DebugView](http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx) which allows you to monitor the debug console. – Rowland Shaw Sep 20 '13 at 11:13

1 Answers1

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.

Jost
  • 1,469
  • 12
  • 18