... " /> 欧美91精品久久久久网,天天视频污软件

php通過(guò)proc_open函數(shù)調(diào)用命令行來(lái)實(shí)現(xiàn)同一線程多次命令行

位置:首頁(yè) / 新聞中心 / 知識(shí)教程

知識(shí)教程 Admin 2024-02-23 18:06:30 796

案例如下:

$command        = "ffmpeg -f v4l2 -pix_fmt mjpeg -i /dev/video0 -acodec aac -b:a 48k -ar 44100 -f mp4 -r 25 -s 1920x1080 -b:v 10M  $filename";
$descriptorspec = array(
0 => array("pipe", "r"),    //標(biāo)準(zhǔn)輸入,子進(jìn)程從此管道讀取數(shù)據(jù)
1 => array("pipe", "w"),    //標(biāo)準(zhǔn)輸出,子進(jìn)程向此管道寫入數(shù)據(jù)
2 => array("file", "error-output.txt", "a")    //標(biāo)準(zhǔn)錯(cuò)誤,寫入到指定文件
);
$process        = proc_open($command, $descriptorspec, $pipes);
stream_set_blocking($pipes[1], 0);   //非阻塞
if (is_resource($process)) {
// $pipes 現(xiàn)在看起來(lái)是這樣的:
// 0 => 可以向子進(jìn)程標(biāo)準(zhǔn)輸入寫入的句柄
// 1 => 可以從子進(jìn)程標(biāo)準(zhǔn)輸出讀取的句柄
// 錯(cuò)誤輸出將被追加到文件 /tmp/error-output.txt
do {
$i = cache('end_record') ? cache('end_record') : 0;
sleep(2);
}
while ($i == 0);
 
fwrite($pipes[0], 'q'); // 結(jié)束指令
fclose($pipes[0]);
 
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// 切記:在調(diào)用 proc_close 之前關(guān)閉所有的管道以避免死鎖。
$return_value = proc_close($process);
// 修改緩存值為0,為下次錄制重置條件
cache('end_record', 0);
// 添加文件到數(shù)據(jù)庫(kù)
$uid                 = '10000001'; // TODO 修改為正式的客戶端ID
$data['uid']         = $uid;
$data['code']        = $param['file_id'];
$data['videoPath']   = 'public/' . $filename;
$data['is_upload']   = 0;
$data['need_upload'] = intval($param['need_upload']);
$data['create_time'] = time();
$id                  = Db::name('common_file')->insertGetId($data);
 
$this->cut(ROOT_PATH . $filename, $filepath, $id,$param['file_id']);
// echo "command returned $return_value ";
}

以上就是“php通過(guò)proc_open函數(shù)調(diào)用命令行來(lái)實(shí)現(xiàn)同一線程多次命令行”的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注木子天禾科技其它相關(guān)文章!


以上就是“php通過(guò)proc_open函數(shù)調(diào)用命令行來(lái)實(shí)現(xiàn)同一線程多次命令行”的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注木子天禾科技其它相關(guān)文章!

15934152105 掃描微信