How to "develop" the process of converting video to background in php?

I have a Flash batch upload script that uploads video files to a directory. Just. Once the download is complete, it creates a mysql entry for that file and moves on to the next file in the queue.

Just before that, I want it to call a background process that converts the downloaded avi avi file to an ipp compatible mp4 file and also generates some preview previews. As you can imagine, it takes a while ... I can just put the conversion code in the file uploader ... but it will hang for every file in a good 10-20 minutes, which is neo- (even you have a function only for administrator).

So, I want it to convert the conversion process in the background and move to the next download while it converts the file.

Would something like this do, or do I really need to use php fork functions?

exec("/usr/bin/php ./convert.php?id=123 > /dev/null 2>&1 &");

      

+2


source to share


3 answers


The php man page for exec () says:

If a program is started with this function, to continue running in the background, the program's output must be redirected to a file or other output stream. failing for this PHP will hang until program execution completes.



So yes, your exec call will do the trick.

+1


source


The best way to implement this architecture is with a work queue, and your PHP frontend feeds the daemon to the backend files for conversion. Separate PHP from your work and your UI will always be responsive.

I haven't written PHP in a long time, but I understand that any process runs under the maximum timeout rule, and runs under the web server. You don't want it to be like this; you certainly don't want the web request to be able to start additional processes.



Write a simple daemon that runs outside of the web server and looks in the folder for the downloaded files. Your web interface dumps them there and your daemon generates a thread for each transformation up to the number of cores you have. Architecturally, this is the smarter choice.

See my answer to this question , which is also relevant.

+1


source


It will be a trick, but it seems like an uncontrollable idea. If you're just going to run and never look back, things might not go so fast.

How simple is it to schedule a script that runs every few minutes and polls whatever is in the queue. Do you have cron access?

0


source







All Articles