Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use multithreading in php

I am now developing a website about sharing videos in the Internet . the flow is as follows: the user upload the video -> the server-side receives the video and uses ffmpeg to convert the video format to flv -> the user goes on doing other things in the site. now I want to establish another thread to do the convert work(use ffmpeg to convert the video format to flv) such that the user can do other thing without waiting the video converted to flv. but don't know how!

like image 786
jianzaixian Avatar asked Dec 17 '22 00:12

jianzaixian


2 Answers

PHP does not support threads. You should use background tasks run by a cron script to do that.

You could have a table with the jobs to be processed, for example, containing the file name on disk, the status (pending, converting, ready), etc, then have a script take all the pending jobs, change their status to converting, convert the files, then change the status to ready. This way you can also present the information to the user, and you could have multiple scripts running if you wish to convert more than one file at the same time.

like image 193
rid Avatar answered Dec 29 '22 00:12

rid


Looks like a job for a job server. Just add it as a background task

like image 38
KingCrunch Avatar answered Dec 28 '22 22:12

KingCrunch