My idea is to forward the PHPSESSID with the request that ERunActions::runBackground() initiates for the background task, so i modified ERunActions::touchUrlExt() as follows:
public static function touchUrlExt($url,$postData=null,$contentType=null,$httpClientConfig=array())
{
// ...
// > INSERTED
$client->setCookie('PHPSESSID', $_COOKIE['PHPSESSID']);
// <
$client->request($method);
}
To test this, I put the following action inside a controller:
public function actionTest($id)
{
if (ERunActions::runBackground($useHttpClient = true))
{
$uid = Yii::app()->user->id;
Yii::log("Starting background for user $uid...");
usleep(10 * 1000000);
Yii::log("...finished.");
Yii::app()->end();
}
else
{
Yii::log("Foreground.");
Yii::app()->user->setFlash('notice', 'Foreground.');
$this->redirect(array('view','id'=>$id));
}
}
If I do not set the cokie (unmodified ERunActions::touchUrlExt()), I receive the page redirected to immediately, and the background does its job, but Yii::app()->user->id is undefined (as expected). With the modified Version (setting the PHPSESSID-Cookie) the background job gets the right user id, but the redirection only occurs after the background process finished (and flash message not appearing). The foreground log message is written immediately, though. The redirection appears to be blocked in some way.
I guess its not a runactions issue, but rather my approach is just too naive. If somebody could enlighten me...I appreciate!
This post has been edited by fl007: 30 July 2012 - 09:22 AM

Help















