javascript-php asynchronous video processing problems? Seeking the guidance of the Great God

Source: Internet
Author: User
Requirements Description:
Using the video solution of the Baidu Cloud platform, its solution is to upload the mobile phone to its own server, and then uploaded by its own server to Baidu server, now hope that the PHP background in the completion of the user upload to their own server, the return user upload success, and then perform the upload to Baidu server operation. The problem is that the PHP backend waits for all execution to complete before it returns to the client. Every time, it will be a long time.

I wonder if the gods can guide the boy? Do front-end, PHP beginner, encountered a lot of problems, thank you to the great gods.

Reply content:

Requirements Description:
Using the video solution of the Baidu Cloud platform, its solution is to upload the mobile phone to its own server, and then uploaded by its own server to Baidu server, now hope that the PHP background in the completion of the user upload to their own server, the return user upload success, and then perform the upload to Baidu server operation. The problem is that the PHP backend waits for all execution to complete before it returns to the client. Every time, it will be a long time.

I wonder if the gods can guide the boy? Do front-end, PHP beginner, encountered a lot of problems, thank you to the great gods.

If your PHP service is using PHP-FPM, you can open a pool of process pools to handle video uploads, and the script will perform time-consuming upload processing with fastcgi_finish_request quickly responding to user requests.


  
   

在文件上传过程中PHP-FPM并不会被阻塞,因为Nginx接收完上传的内容后才一次性交给PHP-FPM.
"从自有服务器上传至百度服务器"这个操作则会阻塞占用一个PHP-FPM工作进程.
这时可以考虑建立的upload进程池来处理这个操作,避免阻塞系统的其他脚本运行.

nginx.conf: upload.php脚本的处理都交给监听9001的PHP-FPM进程池处理location = /upload.php { include fastcgi_params; fastcgi_pass 127.0.0.1:9001; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;}php-fpm: 正常的脚本由静态www池处理,网络阻塞脚本由动态upload池处理[www]listen = 127.0.0.1:9000pm = staticpm.max_children = 4[upload]listen = 127.0.0.1:9001pm = dynamicpm.max_children = 8pm.start_servers = 4pm.min_spare_servers = 4pm.max_spare_servers = 4

可以使用队列,用户传完之后直接压一个任务到队列里然后返回上传完成,系统再执行个定时任务去跑这个队列。队列应用形式有好几种,你搜搜看

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.