I am trying to organize the update of the ProgressBar strip when processing the file with the price list. Here is the code on the client:

$('.import').on('beforeSubmit', function () { var formData = new FormData(this); $.fancybox({ 'scrolling' : 'no', 'overlayOpacity': 1, 'closeBtn': false, 'width': 628, 'height': 208, 'helpers' : { 'overlay' : { 'closeClick': false} }, 'autoSize' : false, 'content' : '<div class=\"progress-striped progress import-progress\" id=\"w0\"><div style=\"width:0%\" aria-valuemax=\"100\" aria-valuemin=\"0\" aria-valuenow=\"10\" role=\"progressbar\" class=\"progress-bar-info active progress-bar\"><span class=\"sr-only\">0% Complete</span></div></div><p class=\"progress-per\">Выполнено 0%</p><p class=\"progress-time\">Осталось 0 минут 0 секунд</p>' }); setInterval(function(){ $.ajax({ url: '/admin/price/progress', method: 'GET', cache: false, processData: false, headers: {Connection: close}, mimeType:'multipart/form-data', contentType: false, dataType: 'json', complete: function(res) { var im = res; var per = (im.row*100/im.totalRow); var sec = 0; console.log(im); $('.progress-striped > div').css('width', per + '%'); $('.progress-per').text('Выполнено ' + per + '%'); sec++; secEnd = 100 - per * sec; $('.progress-time').text('Осталось ' + secEnd/60 + ' минут ' + secEnd%60 + ' секунд'); }, }); return false; }, 1000 ); $.ajax({ url: $('form').attr('action'), method: 'POST', data: formData, cache: false, processData: false, mimeType:'multipart/form-data', contentType: false, complete: function(res) { $.fancybox.close(); }, }); return false; }); 

In action with price processing

 <?php ... \Yii::$app->session->set('import', ['row' => $row, 'totalRow' => $highestRow]); ... ?> 

In the action with getting the line on which the script stopped

 return json_encode(Yii::$app->session->get('import')); 

Why are the requests for / admin / price / progress hang until / admin / price / import

enter image description here

Tell me where I was wrong?

    1 answer 1

    PHP has a so-called blocking session mechanism. This means that while one session is open in one process, others cannot read it. If the reason is this, then you have to somehow change the session handler, for example, you can write them to the database (but keep in mind that in this case there can be typical problems of synchronous access - for example, that data is written to the session an earlier query, which, however, ends later than the second).

    • Without recourse to the session also works incorrectly. I'm afraid that the problem of "hanging" requests is not that. - LANSELOT
    • @LANSELOT does not need to be accessed, it is enough for the framework to call session_start() . - etki
    • Removed read / write from session from code, but did not help .. - LANSELOT
    • @LANSELOT does not need to be accessed, it is enough for the framework to call session_start (). - etki