0

Good day to all.

I need to send a request to a script and then to execute some commands (basically I need to start ffmpeg when clicking on a link).

I tried this:

exec("ffserver &");
exec("ffmpeg -i pipe.avi output.avi");
exec("mplayer -dumpstream someinput -dumpfile pipe.avi");

and this

shell_exec("ffserver &");
shell_exec("ffmpeg -i pipe.avi output.avi");
shell_exec("mplayer -dumpstream someinput -dumpfile pipe.avi");

In both cases I got timeout. Can any1 help me with this? Thank you.

1
  • Note: Seems like after running the shell variant I get timeout whatever I do :| so... can any1 also add a note how do I repair my php parser? (if not i'll just reinstall apache) Commented Mar 29, 2011 at 8:58

3 Answers 3

1

You could try this, its has been posted by user bahri at bahri dot info as a comment to the PHP manual entry for exec

<?php
  function PsExecute($command, $timeout = 60, $sleep = 2) {
        // First, execute the process, get the process ID

        $pid = PsExec($command);

        if( $pid === false )
            return false;

        $cur = 0;
        // Second, loop for $timeout seconds checking if process is running
        while( $cur < $timeout ) {
            sleep($sleep);
            $cur += $sleep;
            // If process is no longer running, return true;

           echo "\n ---- $cur ------ \n";

            if( !PsExists($pid) )
                return true; // Process must have exited, success!
        }

        // If process is still running after timeout, kill the process and return false
        PsKill($pid);
        return false;
    }

    function PsExec($commandJob) {

        $command = $commandJob.' > /dev/null 2>&1 & echo $!';
        exec($command ,$op);
        $pid = (int)$op[0];

        if($pid!="") return $pid;

        return false;
    }

    function PsExists($pid) {

        exec("ps ax | grep $pid 2>&1", $output);

        while( list(,$row) = each($output) ) {

                $row_array = explode(" ", $row);
                $check_pid = $row_array[0];

                if($pid == $check_pid) {
                        return true;
                }

        }

        return false;
    }

    function PsKill($pid) {
        exec("kill -9 $pid", $output);
    }
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I'll try it in a min... just after I repair apache :).
1

If this is only a timeout error, try putting set_time_limit(xx); on top of your code. With xx corresponding to the time to wait in seconds.

Putting 0 means no time limit, but it may be endless if your script enters an infinite loop, of if it is waiting a feedback from your encoding command that never arrives...

Comments

1

Try to increase PHP script execution time in your php.ini file or by setting the function set_time_limit

Comments

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.