0

我以前从未这样做过,所以我需要一些输入。

代码(一般):

$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”包含几个功能。我需要在免费中启动一个特定的函数“SomeFunction()”,同时用户继续。
函数“SomeComponent::SomeFunction()”生成一堆 pdf,与数据库交互并使用 Cakephp 特定的方法'n'crap 来完成所有这些。用户通过数据库接收输出,所以我不需要从函数本身检索它。
所以我不清楚哪种方法可以做到这一点,哪种方法最好使用,以及每种方法的缺点是/可能是什么(特别是安全问题)。

我希望我以一种可以理解的方式解释了一切。如果你已经读到这里 - 谢谢。

4

1 回答 1

0

该过程“SomeComponent::SomeFunction()”是否耗时太长?如果答案是肯定的,那么我会将该函数包装在一个 shell中,如果你想将它提升到一个新的水平,我会使用一个观察者来调度该后台进程。

下面介绍 CakePHP 中的事件处理。

于 2013-11-25T20:32:29.313 回答