Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backtick/shell_exec problem 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I need to collect output from a rather finicky program in my script. The program will occasionally hang and otherwise be annoying.

I'm calling it with the backtick operator (functionally equivalent to shell_exec).

All I want to do is put some sort of timeout on this call.

As it stands, if I intentionally hang the program (remove the stored password from the server), the page just hangs and hangs, starting up 3 processes on the server

php.exe
CMD.exe
and the executable I've called

All protected so I can't even kill the buggers by hand.

So, can I timeout the backtick, or is there some other good workaround to this problem, it seems like the kind of thing which would be useful.

the PHP.exe service does eventually kill itself (after way too long), but the other two are sticking around... assumbably waiting for a password, without anyway out.

-Rob
 
Ok, I take it back, I can kill the processes, but only by using the Kill command, not by using the taskmanager...

did I mention I'm running IIS 4 in WindowsNT?

-Rob
 
I inferred Win32 on NT, W2K, or XP from the mention of "cmd.exe".

The app you're calling from PHP -- is there any way to improve it? Win32's process management is execrable, partly because Win32 is better at spawning threads than processes, partly because as a user, you're not supposed to be interested in that kind of thing. Want the best answers? Ask the best questions: TANSTAAFL!
 
Unfortunately not, the program is 3rd party, heavily used, and here to stay.

And I'm running just fine, I've just been warned that sometimes this won't be the case.

All I'd like to do is say

$output = `blah.exe`;

and if blah.exe doesn't return anything after a number of seconds, just shut down the cmd window and be done with it... I can also possibly improve the program with a batch file or some such if those could give me the same functionality, I'm perfectly find getting no data returned, or getting a crash of the shell. I'm just not ok waiting forever, and somehow this shell call gets passed the 30 second max executable time I have set for PHP scripts in my PHP.ini file.

Grrrrr.

-Rob
 
Is it possible after a set amount of time passes to send a signal to the currently executing shell?

Namely the ^C signal? Or however that works in windows?

-Rob
(ctrl-c does kill the program)
 
I can't see a way of doing this without using pcntl_fork. --BB
 
Woohoo, and I thought that class on forks I barely kept my eyes open for would never be useful... thanks much BB101 I had no idea PHP had support for this.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top