i’m trying to use the session (currently set to use dbSession) to communicate between a long running process and an ajax request for progress and i can only make it work one direction.
in my process i have the following:
if( Yii::$app->session['cancel-processing'] )
{
// cancels download
error_log( 'download canceled' );
return 1;
}
$new_progress = round( $downloaded / $download_size * 100 );
if( $progress != $new_progress )
{
$progress = $new_progress;
error_log( 'progress: '.$progress );
Yii::$app->session['processing-progress'] = $progress;
Yii::$app->session->close();
}
this works in setting the ‘processing-progress’ session variable which is retrievable via my ajax request. however in a different ajax request i set the ‘cancel-processing’ session variable and it never works.
Yii::$app->session['cancel-processing'] = true;
Yii::$app->session->close();
i have tried various combinations of session->open, session->close and session->destroy. there is no way i can force it to write and save to the session in my ajax post and then have that session variable accessible in my long running php script. how else am i supposed to communicate with this process without using file persistence or my own database table?
it appears that one of the processes overtakes the other unpredictably. generally the long running process, which is constantly updating the session, prevents the ajax process from actually writing to the session. why would this possibly be expected behavior? also: why do i have to close the session for the variable to be written? its just using the database. is it not expected behavior for it to write to the database as soon as the session variable is set? frustration level to the max.