Running Yii2 on Ubuntu 16.04. I want to start a background task and then query it's status. The task starts fine, but queries from the client doesn't get a response until the server task ends.
Server Code
function actionRun($arguments)
{
$paramsJson = json_encode($arguments);
$script = 'php /var/www/html/app/yii consolecontroller/action';
$command = "{$script} '{$paramsJson}' > /dev/null 2>&1 &";
exec($command);
}
Client Code
$('#buttonSubmit').on('click', function (event) {
event.preventDefault();
setTimeout(function () {updateJobProgress();}, 100);
$.ajax({
url: printForm.attr('action'),
type: 'post',
data: printForm.serialize()
});
function updateJobProgress() {
var reportJob = $('input[name="reportJobId"]');
$.ajax({
url:reportJob.data('status'),
data:{reportJobId: reportJob.val()},
success:function(data) {
if (data.progressStatus < 5000) {
reportJob.html('processing');
} else {
reportJob.html('done');
}
}
});
setTimeout(function() {updateJobProgress();}, 700);
}
});