This is a great idea! So whichever script starts encoding, it takes
place in the $LOCKS folder, then everytime before a new script starts
running it will always check if the "$LOCK room" is empty, and runs
only if it's empty. Brilliant! See how far I can go with all the
ideas...

THANK YOU, Ryan!!



On Feb 28, 2:21 pm, Ryan Schmidt <[email protected]> wrote:
> On Feb 28, 2011, at 12:42, Tan Cheng wrote:
>
> > Thanks for all the input!!! So much good information to learn. Due to
> > the tight budget and maybe the site traffic will not be so high, I am
> > still looking at a shard hosting which supports cron, and maybe let it
> > run a cake shell every 5 hours to encode and update the database. I
> > think I am going to do some testing on my ubuntu localhost first. My
> > goal here may to get my feet wet before thinking about vps with a
> > queue system.
>
> The advantage of having a single daemon that just keeps on running is that 
> you don't have to worry that there's another copy of the daemon running at 
> the same time, possibly competing for encoding the same video. If you run the 
> script via cron on an interval, it is possible that the script will take 
> longer than that interval to run, which would introduce this problem. So if 
> you're going to do this, then you have to handle it, for example by ensuring 
> only one copy of the script can encode videos at a time. A lock file would be 
> one simple idea that could work. (Designate a directory to contain locks, 
> let's say "$APP/encoder/locks" (hereafter "$LOCKS"). When the daemon starts, 
> create (touch) an empty file "$LOCKS/$UNIQUE" where $UNIQUE is something 
> unique to this encoder instance, for example its process id or better yet a 
> generated a UUID. Then check if there are any files in $LOCKS other than 
> $UNIQUE. If there are, that means there are other encoders running; delete 
> the lock and exit and do no encoding. Otherwise, proceed with encoding videos 
> as discussed before, except instead of looping forever, loop until there are 
> no more videos to encode, then delete the lock and exit.) With this in place, 
> you could schedule the script to run as often as you like (every hour, every 
> half hour, every 5 minutes) to guarantee users' videos are encoded as quickly 
> as you need, without risk of the script competing with another instance of 
> itself.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to