My question may be a bit complicated.
This is my scenario:
I want to start the mjpg streamer using php. My php script is:
<?php
$output = shell_exec("sh /var/www/html/shellstart.sh");
echo "<pre>$output</pre>";
header("Location: ../index.php");
?>
It works fine in starting the script. The problem is that the script
shellstart.sh:
LD_LIBRARY_PATH=/opt/mjpg-streamer/mjpg-streamer-experimental/ /opt/mjpg-streamer/mjpg-streamer-experime $
starts a process and the header() function is never called, because it never leaves the script. So I am looking for a method to start the script, keep it running but return to the php script and call the header() function.
I already tried
trap "exit" SIGINT
and
nohup LD_LIBRARY_PATH=/opt/mjpg-streamer/mjpg-streamer-experimental/ /opt/mjpg-streamer/mjpg-streamer-experime$
also I tried $ disown. But when using nohup or $ disown the script won't even start the process.
I appreciate any help! Thanks in advance.
You want to try something like:
$pid = exec("sh /var/www/html/shellstart.sh> /dev/null 2>&1 & echo $!; ", $output);
This will make the script start in the background and return you the PID of the script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With