help in invoking an external program

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

help in invoking an external program

Post by jasongr »

Hello people

I have a PHP script that attempts to invoke an external shell command.
The shell command is an executable written in C++.
The executable program spawns a new thread which inokes PHP again using c:\php\php.exe and the original thread returns immediately to the call (the original PHP script)

here is what I expected to happen:
Script a.php invokes command shell:

Code: Select all

exec("c:\program.exe", $output, $returnValue);
program.exe spawn a new thread which invokes c:\php\php.exe on new script b.php
The orignal thread in program.exe shouldn't wait for b.php to complete (as this is a different thread), and immediately terminate, causing the code to return to a.php
so a.php continues to run while in the backgound, b.php is still running...

However, what is happening is that
the code doesn't return to a.php until b.php terminates.
I checked my program.exe code and it is flawless.
In fact, if I invoke program.exe directly from the command line, program.exe terminates immediately and b.php is running in the background...

I even tried using system instead of exe
In both cases, I get the same problem

any help would be appreicated

thanks
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

try uses a loop maybe

Code: Select all

while(condition1) {
exec("c:\program.exe", $output, $returnValue); 
}
or try a do-while loop?
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

why would a loop help me?

I want the executable to be invoked just once. The problem is that the flow of the code is not resumed as soon as the executable is invoked
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you read the user contributed notes at http://de2.php.net/manual/en/function.exec.php ?
Some of them deal with background tasks under win32.

btw:
jasongr wrote:The orignal thread in program.exe shouldn't wait for b.php to complete (as this is a different thread)
Not thread, exec() create a new process.
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

Post by jasongr »

I solved the problem by using psExec
http://www.sysinternals.com/Utilities/PsExec.html
Post Reply