Jump to content

[THREADING] Open a child script, independent from the main code (opened)


flaab

Recommended Posts

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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.