0

I've never done this before, so I need some input.

Code (in general):

$cofig = Configure::read('config');
    if ($config['stuff'] == 1){
      $this->Session->setFlash('it is already done this month');
      $this->redirect('/to/some/where');
    }
    elseif ($config['stuff'] == 2){
      $this->Session->setFlash('it is already running');
      $this->redirect('/to/some/where');
    }
    else {
      SomeComponent::SomeFunction(); //this I need to launch in background while user continues further
      $this->Session->setFlash('you have launched it');
      $this->redirect('/to/some/where');
    }

"SomeComponent" contains several functions. I need to launch a specific function "SomeFunction()" in the bacground while user continues further.
Function "SomeComponent::SomeFunction()" generates bunch of pdfs, interacts with database and uses Cakephp specific methods'n'crap to do all that. Users receive output via database, so I don't need to retrieve it form the function itself.
So i'm not clear which method can do that, which best to use and what are/may be drawbacks of each one (security issues in particular).

I hope I explained everything in a understandable way. If you have read this far - thanks.

uldo
  • 19
  • 2
  • 8

1 Answers1

0

Is that process "SomeComponent::SomeFunction()" taking too long? If the answer is yes then I would wrap that function in a shell and if you want to take it to the next level I would use an Observer in order to dispatch that background process.

Here is an introduction to Event Handling in CakePHP.

Guillermo Mansilla
  • 3,779
  • 2
  • 29
  • 34
  • I came back to this project and created Observer pattern with CakeEvent. Everything works fine up to one point - user still has to wait until it completes (not dispatching as seperate process). I wouldnt say it takes too long, but it's long enough for user to interrupt it by refreshing, backing up or whatever magic the end-user is wielding. – uldo Jan 02 '14 at 18:23