4

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.

1

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That worked like a charm! I will research how this works. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.