开发者

Proc_open read and parse output - real-time

When I run proc_open with a file.txt path for the stderr output, that file is constantly updated every couple seconds with output of the proc_open program I am running which is ffmpeg. I just want to redirect that output to a phpfile where it can be read and parsed but while 开发者_如何学JAVAthe process is running (so send info every couple seconds) so I can update a database. IS this possible? I have been googling for hours so if there are any experts out there who actually know how to use this function of have experience in this I would greatly appreciate any help.

this puts output in a text doc. If I change to 2 => array("pipe","w") and the echo the output only comes on my screen at the end of the process

$descriptorspec = array(
0 => array("pipe","r"),
1 => array("pipe","w"),
2 => array("file","/home/g/Desktop/test.txt","a")
) ;

$cwd = './' ;
// open process /bin/sh
$process = proc_open("/usr/local/bin/ffmpeg -i /home/g/Desktop/vid.wmv /home/g/Desktop/vid.flv", $descriptorspec, $pipes, $cwd) ;


  1. you could run ffmpeg like this:

    ffmpeg ..optinons... 2>&1 | php script.php
    

But you could have in input STDERR and STDOUT of ffmpeg

  1. And second normal decision:

    <?
    $cmd = 'ffmpeg -i /home/azat/Desktop/src.avi -y /home/azat/Desktop/dst.avi';
    $pipes = array();
    $descriptors = array(2 => array('file', '/tmp/atest.log', 'a'));
    
    $p = proc_open($cmd, $descriptors, $pipes);
    
    while (true) {
            sleep(1);
    
            $status = proc_get_status($p);
            if (!$status['running']) break;
    
            echo "STEEL RUN\n";
            // some manupulations with "/tmp/atest.log"
    }
    

Also you can see this class - it is a wrapper for exec processes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜