flaab Posted February 3, 2007 Share Posted February 3, 2007 Good night everyone!! I'm from Spain so sorry about my grammar mistakes xD. I'll go straight to the point: I'm programming an Online Game that uses video feeding as an important part of it. I've decided that all the videos displayed in the web are going to be encoded with FLV format. This means i've to run a script behind the web to encode each video uploaded by users to FLV format. I've already created those Scripts using the following and a bit more stuff. They work just fine. system("ffmpeg -whatever args -are neccesary"); My problem is the following. I 've to launch those php encode scripts right after a video upload is completed by the user. But I must avoid the user to wait for that to finish, because it might take a long while, depending of how busy the server is at the moment. So I need sort like this in pseudocode: ( * lines are solved) > Receive video upload from user * > Once it's completed, launch convert script. -------------------------------------------- > Users goes away to navigate or whatever, while his video is still being converted. * | > Video encoding is finished. Mysql fields are updated. * <-------------------------------- I hope have been clear enough for you to understand my problem. Hope to receive answers =) Thanks in advanced. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/36853-threading-open-a-child-script-independent-from-the-main-code-opened/ Share on other sites More sharing options...
redbullmarky Posted February 3, 2007 Share Posted February 3, 2007 i had a quick look around on Google and what seemed to be the recurring theme is using the exec command to execute a background script via the shell. Might be a good start although someone here may have a better way... Quote Link to comment https://forums.phpfreaks.com/topic/36853-threading-open-a-child-script-independent-from-the-main-code-opened/#findComment-176006 Share on other sites More sharing options...
448191 Posted February 3, 2007 Share Posted February 3, 2007 I'd swear I came across a very simple solution in the user contributed notes in the manual, but I can't find it. Anyway, best I can come up with of the top off my head: use sockets to connect to the script that is encoding, cut the connection but let the script continue to run (set timeout to 0). Quote Link to comment https://forums.phpfreaks.com/topic/36853-threading-open-a-child-script-independent-from-the-main-code-opened/#findComment-176039 Share on other sites More sharing options...
flaab Posted February 3, 2007 Author Share Posted February 3, 2007 Hi =) Maybe i'm wrong but i think that "exec whatever" will keep the user waiting till it's finished...right? If not, that is my solution xD. About sockets...i don't know anything about them...How would that be done? Thx in advance. Quote Link to comment https://forums.phpfreaks.com/topic/36853-threading-open-a-child-script-independent-from-the-main-code-opened/#findComment-176153 Share on other sites More sharing options...
utexas_pjm Posted February 3, 2007 Share Posted February 3, 2007 On a *nix system you can fork the process: <?php //... exec('php someScript.php &'); //... ?> I think this is the closest you can come to emulating a multi-threaded process in PHP. Best, Patrick Quote Link to comment https://forums.phpfreaks.com/topic/36853-threading-open-a-child-script-independent-from-the-main-code-opened/#findComment-176206 Share on other sites More sharing options...
shoz Posted February 3, 2007 Share Posted February 3, 2007 Although possibly not applicable to this question there is pcntl_fork() which would allow forking in the traditional sense. I'd swear I came across a very simple solution in the user contributed notes in the manual, but I can't find it. It may have been this. Something similar to what utexas_pjm suggested http://www.php.net/manual/en/function.exec.php#38451 One other approach that you may want to consider in addition to the others already mentioned is to store the filename in a "tobeencoded" table and have a daemon of some sort check the table for new submissions. I suppose the approach you choose will depend on how the "Video Feeding" is relevant to the game. Quote Link to comment https://forums.phpfreaks.com/topic/36853-threading-open-a-child-script-independent-from-the-main-code-opened/#findComment-176254 Share on other sites More sharing options...
448191 Posted February 4, 2007 Share Posted February 4, 2007 It may have been this. Something similar to what utexas_pjm suggested Nah, that wasn't it. The reason I remembered it was because it was a solution that doesn't require root access. It think it made use of a quirck.. If only I could remember the function it was posted with... I wish I bookmarked it.. I hate this. Quote Link to comment https://forums.phpfreaks.com/topic/36853-threading-open-a-child-script-independent-from-the-main-code-opened/#findComment-176437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.