Using ffmpeg, PHP and beanstalk
Asked Answered
R

1

2

I am very new to ffmpeg and beanstalk and I need a little help. I want to use beanstalk to queue files for ffmpeg to convert. I've downloaded, installed and started beanstalkd (also installed libevent as it suggests to) and i've downloaded a PHP client for beanstalkd;

http://sourceforge.net/projects/beanstalk/

Now after download the client and putting it on my server, I have done nothing but use the example from the client and i'm getting this error;

Fatal error: Maximum execution time of 30 seconds exceeded in /Users/wasimkhamlichi/Sites/vibenation/beanstalk/src/BeanStalk.class.php on line 1138

This is the code from the example;

$beanstalk = BeanStalk::open(array(
    'servers'       => array( '127.0.0.1:11300' ),
    'select'        => 'random peek'
));

// As in the protocol doc.
$beanstalk->use_tube('foo');

// As in the protocol doc.
$beanstalk->put(0, 0, 120, 'say hello world');      // Add a job to the queue with highest priority, 
                                                    // no delay, 120 seconds TTR, with the contents
                                                    // 'say hello world'.

                                                    // NOTE: the put() method here supports a final optional 
                                                    // argument, a tube name. If supplied, the server will
                                                    // first switch to that tube, write the job, then switch
                                                    // back to the old tube again.

// As in the protocol doc.
$job = $beanstalk->reserve();                       // Assuming there was nothing in the queue before 
                                                    // we started, this will give us our 'hello world'
                                                    // job back.

// This is a BeanQueueJob object.
echo $job->get();                                   // Output: 'say hello world'

Beanstalk::delete($job);                            // Delete the job.

Very simple quick script just to say hello but it's timing out. Can anyone help please?

Radiopaque answered 8/4, 2011 at 8:4 Comment(7)
Which client library are you using?Gurgitation
Hi, it's php beanstalkd client by iceyliquid - find it here - sourceforge.net/projects/beanstalkRadiopaque
Can you make sure that the job is really put into the queue? Use may use set_time_limit(0) to prevent the script timeout. Make sure beanstalkd is really running on that port.Gurgitation
The job is definitely in the queue, and the server is definitely on that port. I changed the set_limit_limit(0) but the page just hangs forever. I telnet to localhost 11300 and typed stats and this came up --------- OK 813 --- current-jobs-urgent: 1 current-jobs-ready: 1 current-jobs-reserved: 0 current-jobs-delayed: 0 current-jobs-buried: 0 ------- Any ideas?Radiopaque
Ok now i'm using pheanstalk beanstalkd php library, which seems to load fine. I'm really not sure how it works. I want to process ffmpeg from command line, but when i pass beanstalkd the the command, nothing actually happens, ffmpeg doesn't process anything. When I use $pheanstalk->put("message"); - what can I actually pass as the message? ThanksRadiopaque
You can pass anything into the queue. On the other side (a daemon) can interpret that message and execute ffmpeg.Gurgitation
So you mean beanstalkd doesn't actually execute anything, it just stores messages which can be retrieved by another script and executed?Radiopaque
O
2

Beanstalk just passes messages around. You put something into the queue in one place, and take it out somewhere else, later.

You could put a filename into a tube called 'ffmpeg-convert'. A PHP script running from the command line reserves the next item from the queue, and does what it needs to, putting the finished file in an appropriate place.

If you needed more information (for example, where to put the finished file, quality settings or a new output filename), you can encode the information - an array of information converted into a Json string (with json_encode($array)) is a good choice. You put the encoded string into Beanstalk, and the cli-script decodes the string, and does the work.

Running the worker as a command-line based script usually avoids any timeout issues. Unlike a webpage request, there is not a default timeout, also there is more latitude regarding memory use.

Orman answered 12/4, 2011 at 23:4 Comment(3)
Thanks very much Alister. So what's the benefits of using Beanstalkd over a queue in a database?Radiopaque
One benefit is you would have to keep polling the DB, where a beanstalk client can connect and then it will wait till there's a message for it. There are other advantages (and killer features) in a presentation I did, at abulman.co.uk/presentations/Beanstalkd-2010-05-06Orman
Fantastic, brilliant presentation. Thanks for your help!Radiopaque

© 2022 - 2024 — McMap. All rights reserved.