Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.