开发者

getting progress for multiple exec() processes realtime

I have a php script that executes ffmpeg and then it starts working. I can execute this script 4 times and spawn 4 processes. I would like to get progress in real time. How do I get and identify which process is which for each output?

$h = fopen('php://stdin', 'r'); $str = fgets($h);

I know that line will get whatever output is in stdin but how do you separate it? How do I continuously poll for output? Once a process is started, how do you access that output on a conti开发者_如何学编程nuous basis? I know you need ajax but what php method will allow you to access that info and separate it from other processes. Some have suggested directing output to a text file and getting the contents, but is this the only way? Why keep making more text files for each process? Another suggested redirecting output using 2>&1 | php script.php after the command. This only gets output at the start of the process since the file executes once.

I have been struggling with this for a while and am getting closer, so any expert help would be so appreciated.

See Edit

$process = exec("/usr/local/bin/ffmpeg -i /home/g/Desktop/cave.wmv -deinterlace -acodec libfaac -ab 96k -ar 44100 -vcodec libx264 -s 480x320 -f flv /home/g/Desktop/file.flv")


This is a bit complex. As far as I know exec blocks the PHP thread until it completes. I think ffmpeg can write it's progress to a file. You'd need to parse that file to get the progress. You'll want to call that with Ajax.

You need to figure out how you can get ffmpeg to report it's progress, the rest is easy :P


If only 4 processes should be running at a time, I really see no reason not to create 4 text files and directing the output of ffmpeg into those. After that it's just a question of reading those text files with PHP.

If you intend to make this HTTP operateable, you could create two scripts: start_process.php and process_status.php. The first file would take an ID as input, starting an ffmpeg process, continuously reading its progress and reporting to a MySQL database. process_status.php would take the same ID as input and report the status from MySQL to the user. You could hook that file up to Ajax and get live updates.

You would have to polish the solution with checking for double entry of the same ID, perhaps automatically creating an ID and returning it from start_process.php etc.


You should probably create an array for the four processes. Start your processes with proc_open and slap the returned resource in your array. You could then poll your the array looking at the output for each process resource.

http://us2.php.net/manual/en/function.proc-open.php

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜