Sunday, February 27, 2011

how to redirect and let the server do some lengthy job in the background?

Hi everyone,

I have a question. I'm using cakephp to develop a video site, like
youtube, I want the user to upload their video to the site, but I only
want them to wait for the upload, after it is uploaded, I hope the
converting process ( using ffmpeg ) run in the background and they
will be redirected to a different page. I read in some posts that if I
set the $exit parameter of redirect() to false, it will redirect
immediately and execute the code after that. So I specified it to
false.

The problem in my application is, when a video is uploaded, the page
does not redirect me immediately to the "videos=>index" page, I still
have to wait for the converting process to be done, then I will be
redirect to the "videos=>index" page. So how can I be immediately
directed before the video converting starts?

Here is a code snippet of my function :

if ($this->Video->save($this->data)) {

$this->Session->setFlash(__('The Video has been saved', true));

$this->redirect(array('action' => 'index'),'',false);

$path='/opt/lampp/htdocs/exceltv/app/webroot/uploads/files/
tmp_videos/'.$newFilename.$ext;

$out_path='/opt/lampp/htdocs/exceltv/app/webroot/uploads/files/
videos/'.$newFilename.'.flv';

$path_to_save_image='/opt/lampp/htdocs/exceltv/app/webroot/img/
thumb/'.$newFilename.'.jpg';

// The first this we need to do is convert the video

$this->VideoEncoder->convert_video($path, $out_path, 480,
360,true);

// Then we need to set the buffer on the converted video

$this->VideoEncoder->set_buffering($out_path);

$this->VideoEncoder->grab_image($out_path,
$path_to_save_image);

}

For this Video model, I used an upload behaviour to handle the upload,
so the video has been uploaded before the record it stored in the
database.

Anyone could explain a bit about the flow of the redirect function?

Thanks a lot!!

-David

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: