Jump to content

Start and Stop a Program


jargen

Recommended Posts

PHP doesn't have any way to execute something in the background, which is what you need if you want to launch something then get the PID.  In Linux/Unix you can do this using a simple shell script, such as:

#!/bin/bash

/usr/bin/php -r 'sleep(100);' >/dev/null >&1 &
disown
echo $!

 

And run it:


if (exec('./go.sh', $output, $ret)){
   echo 'Launch successful.  Pid='.$output[0];
}
else {
   echo 'Launch failed';
}

 

For windows, running in PHP would be essentially the same but you would have to find or create a program to use as an intermediary which will launch the program you want in the background, then output it's PID.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.