Php FFMpeg+;Beanstalk:如何在不使用Beanstalk的情况下将进程传递给它或获得相同的结果
我的问题是FFMpeg和Mencoder非常灵活,即使运行一个进程也会使HTTPd变慢,但是(FFMpeg/Mencoder)的多个进程只是完全挂起了它(HTTPd)。例如,我希望使用Beanstalk处理转换 我的具体问题是:如何将我目前的工作转移到Beanstalk 我有一个触发转换的简单PHP代码:Php FFMpeg+;Beanstalk:如何在不使用Beanstalk的情况下将进程传递给它或获得相同的结果,php,ffmpeg,task-queue,beanstalkd,Php,Ffmpeg,Task Queue,Beanstalkd,我的问题是FFMpeg和Mencoder非常灵活,即使运行一个进程也会使HTTPd变慢,但是(FFMpeg/Mencoder)的多个进程只是完全挂起了它(HTTPd)。例如,我希望使用Beanstalk处理转换 我的具体问题是:如何将我目前的工作转移到Beanstalk 我有一个触发转换的简单PHP代码: RunInBackground('convert.php', array($upload, $video_id), $log_path); 现在,Beanstalk正确的代码是什么样子的?如
RunInBackground('convert.php', array($upload, $video_id), $log_path);
现在,Beanstalk正确的代码是什么样子的?如果上传多个视频,这些过程不会同时启动
如果您认为为了满足我的需要,最好使用Beanstalk以外的其他工具,并且您知道如何实现它,我仍然很高兴看到它
提前感谢,伊利亚有两种可能性:
-尝试xuggler进行转换-内联运行,而不必生成作业
-使用数据库或文件创建“文件处理队列”。。让您的转换过程只查询“要处理的未完成文件”,但一次只能运行其中一个文件。它将独立于您的主要任务运行,但可以将其状态发布到您的主要任务可以阅读的地方。例如“忙”或“队列中有3个文件”或“可用”两种可能性:
-尝试xuggler进行转换-内联运行,而不必生成作业
-使用数据库或文件创建“文件处理队列”。。让您的转换过程只查询“要处理的未完成文件”,但一次只能运行其中一个文件。它将独立于您的主要任务运行,但可以将其状态发布到您的主要任务可以阅读的地方。例如“忙”或“队列中有3个文件”或“可用”基于ethrbunny提供的好主意,我决定不使用Beanstalk或Resque就可以实现我的目标!毕竟我非常高兴!我敢打赌,对于那些试图将FFMpeg/MPlayer/MEncoder进程限制为服务器上唯一一个活动进程的人来说,这将是非常有用的,以便能够保持其他进程良好运行,例如httpd 一步一步
// Let's check if ffmpeg, mplayer, mencoder or mediainfo processes are running //
exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
exec("ps ax | grep -v grep | grep mplayer", $mplayer);
exec("ps ax | grep -v grep | grep mencoder", $mencoder);
exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
// As non of them are running we start conversion process //
RunInBackground('convert.php', array($uploaded_file_name , $uploaded_video_id ), $log_file_path);
} else {
// As the ffmpeg or mplayer or mencoder or mediainfo is running we add the process to the queue into the database//
//Connecting to database using ADOdb //
$sql = "INSERT INTO encoding_queue SET queue_timestamp = '" .time(). "',
uploaded_video_id = '" .mysql_real_escape_string($uploaded_video_id ). "',
uploaded_file_name = '" .mysql_real_escape_string($uploaded_file_name ). "',
log_file_path = '" .mysql_real_escape_string($log_file_path). "'";
$conn->execute($sql);
}
<?php
require('path/to/your/config.php');
require('path/to/your/function.php');
exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
exec("ps ax | grep -v grep | grep mplayer", $mplayer);
exec("ps ax | grep -v grep | grep mencoder", $mencoder);
exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
$sql = "SELECT * FROM encoding_queue ORDER BY queue_timestamp ASC LIMIT 1";
$rs = $conn->execute($sql);
$queue = $rs->getrows();
if ( $conn->Affected_Rows() == 0 ) {
die ("Error! There is no records in the database. Nothing to convert. Stopping...");
}
if (file_exists($config['VDO_DIR'] . '/' .$queue[0]['uploaded_file_name'])) {
if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
RunInBackground('convert.php', array($queue[0]['uploaded_file_name'], $queue[0]['uploaded_video_id']), $queue[0]['log_file_path']);
} else {
die ("Another conversion process is still in progress. Stopping...");
}
} else {
die ("Error! There is no video file ".$queue[0]['uploaded_file_name']." found. Nothing to convert. Stopping..."); }
?>
伊利亚基于ethrbunny提供的好主意,我决定不使用Beanstalk或Resque来实现我的目标!毕竟我非常高兴!我敢打赌,对于那些试图将FFMpeg/MPlayer/MEncoder进程限制为服务器上唯一一个活动进程的人来说,这将是非常有用的,以便能够保持其他进程良好运行,例如httpd 一步一步
// Let's check if ffmpeg, mplayer, mencoder or mediainfo processes are running //
exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
exec("ps ax | grep -v grep | grep mplayer", $mplayer);
exec("ps ax | grep -v grep | grep mencoder", $mencoder);
exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
// As non of them are running we start conversion process //
RunInBackground('convert.php', array($uploaded_file_name , $uploaded_video_id ), $log_file_path);
} else {
// As the ffmpeg or mplayer or mencoder or mediainfo is running we add the process to the queue into the database//
//Connecting to database using ADOdb //
$sql = "INSERT INTO encoding_queue SET queue_timestamp = '" .time(). "',
uploaded_video_id = '" .mysql_real_escape_string($uploaded_video_id ). "',
uploaded_file_name = '" .mysql_real_escape_string($uploaded_file_name ). "',
log_file_path = '" .mysql_real_escape_string($log_file_path). "'";
$conn->execute($sql);
}
<?php
require('path/to/your/config.php');
require('path/to/your/function.php');
exec("ps ax | grep -v grep | grep ffmpeg", $ffmpeg);
exec("ps ax | grep -v grep | grep mplayer", $mplayer);
exec("ps ax | grep -v grep | grep mencoder", $mencoder);
exec("ps ax | grep -v grep | grep mediainfo", $mediainfo);
$sql = "SELECT * FROM encoding_queue ORDER BY queue_timestamp ASC LIMIT 1";
$rs = $conn->execute($sql);
$queue = $rs->getrows();
if ( $conn->Affected_Rows() == 0 ) {
die ("Error! There is no records in the database. Nothing to convert. Stopping...");
}
if (file_exists($config['VDO_DIR'] . '/' .$queue[0]['uploaded_file_name'])) {
if(empty($ffmpeg) && empty($mplayer) && empty($mencoder) && empty($mediainfo)) {
RunInBackground('convert.php', array($queue[0]['uploaded_file_name'], $queue[0]['uploaded_video_id']), $queue[0]['log_file_path']);
} else {
die ("Another conversion process is still in progress. Stopping...");
}
} else {
die ("Error! There is no video file ".$queue[0]['uploaded_file_name']." found. Nothing to convert. Stopping..."); }
?>
Ilia您认为使用db队列比使用Beanstalk或Resque更好吗?因为听起来您的部分问题在于控制Beanstalk/etc的运行实例数量。。这就是为什么我建议使用单独的转换机制来维护一个实例。我不知道BeanStalk或Resque,但听起来您的资源有限。您认为使用db queue比使用BeanStalk或Resque更好吗?因为您的部分问题是控制BeanStalk/etc的运行实例数。。这就是为什么我建议使用单独的转换机制来维护一个实例。我不知道BeanStalk或Resque,但听起来你的资源有限。