本文介绍了在运行过程中,当PHP应对阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Ajax请求一些数据时,PHP已经运行很长的脚本;

I'm trying to get some data from Ajax request when already PHP running a long script ;

但是,当阿贾克斯已经回答了在PHP该脚本完成,我需要运行其他脚本在Ajax响应。

but when the Ajax has been answered that script in PHP is completed, and I need to get Ajax response during running other scripts .

JS

setInterval(function(){
    $.post( 'progress.php','',
    function(data){
        $('.-info-').html(data);
    }); 
},100);

progress.php

session_start();
echo $_SESSION['progress'].'%';

running.php

session_start();
$i=0;
while($i<99){
    $i++;
    $_SESSION['progress'] = $i;
    //sleep(1);
    //flush();
}

有没有什么办法来应对,当,而运行?

推荐答案

编辑:马克·B是正确的。该会议将被锁定,不能按要求更新。所以,你需要存储在系统中的进程,你可以从多个连接的异步访问 - 也许数据库

Marc B is right. The session will be locked and not updated as required. So you need to store the progress in an system you can access asynchronously from multiple connections - maybe the database?

running.php:

session_start();
$i=0;
while($i<99){
    $i++;
    // Store progress in Database
}

progress.php:

 session_start();
 //read progress from Database

这篇关于在运行过程中,当PHP应对阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 23:50