腺苷的上述评论是正确的。
“在PHP中,一次只能在一个会话上运行一个脚本,以免覆盖会话数据等。因此,当在同一会话中对PHP脚本进行两次ajax调用时,第二个必须等待第一个完成”
为了加快处理速度,您可以提前写入和结束会话(session_write_close())以释放会话锁,并允许使用该会话的其他脚本继续。
注意:调用session_write_close后,您仍然可以从$ _SESSION变量中读取变量,但是您可能不再对其进行写入。
您可以在此处找到一个很好的示例:PHP会话锁–如何防止阻止请求
上面的链接提供的示例:
<?php// start the sessionsession_start();// I can read/write to session$_SESSION['latestRequestTime'] = time();// close the sessionsession_write_close();// now do my long-running pre.// still able to read from session, but not write$twitterId = $_SESSION['twitterId'];// dang Twitter can be slow, good thing my other Ajax calls// aren't waiting for this to complete$twitterFeed = fetchTwitterFeed($twitterId);echo json_enpre($twitterFeed);?>



