I need response some variables immediately and continue executing another process in Zend Framework 2, this code could help:
public function wstestsAction(){
//This variables needs to be responded immediately
$response["response"] = true;
$response["message"] = "Msg Test";
//This process could take 1 minute
$libraryInstance = new libraryInstance();
$sendData = $libraryInstance->sendData("params");
$varsToView["resultJson"] = \Zend\Json\Json::encode($response);
$viewModel = new ViewModel($varsToView);
$viewModel->setTerminal(true);
return $viewModel;}
In the view (wstests.phtml) I have this code:
<?=$this->resultJson?>
Thanks!!!
I would recommend using a cron task to do processes that take a while. You would need to store the parameters you are looking to send in some type of storage (or even a DB).
From there you could run a cron task every 5 minutes to check for new data to submit/process (using PHP).
This would be the ideal route if you want your pages to render as fast as the others.
Hope this helps.