I’m making an encoding server and need a little help
I have a directory called uploaded, and a php file called videoConverter.php and when it runs It has a loop that will convert all the video files in the uploaded directory and FTP the completed file to a streaming sever.
There is no problem with the script but the problem is once the loop is finished it won’t convert any new files uploaded after the loop ends. I need to find away to execute the php file or script when files are uploaded to the uploaded directory.
I was thinking about using a cron job and running the php file every second, but wouldn’t it keep running the script while it’s already running?
Does anyone know a good way to approach this issue?
I wouldn’t stick with PHP for such a task, it would just be an inefficient layer between the encoding tools and the files themselves – you need an event-driven tool, not a scripting language.
I’d better look at inotify for local changes in the upload folders, then process new files on the go.
My first take would be using inotify wrapper in a Node.js environment:
encode(newFile)is called;pushToFTP(encodedFile)callback is fired and transfer begins.Bonus, smaller files don’t have to wait till the whole job finishes due to asyncronous js architecture.