doufan1363 2012-08-23 02:03
浏览 24
已采纳

如何在目录中存在文件时运行PHP文件 - 编码服务器

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?

  • 写回答

2条回答 默认 最新

  • douhuang1852 2012-08-23 02:20
    关注

    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:

    • whenever a new file appears, encode(newFile) is called;
    • when encoding process is finished, 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题