服务器每个会话只允许一个请求 [英] Server allowing only one request per session

查看:47
本文介绍了服务器每个会话只允许一个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:

xyz.com 的所有页面都使用会话来检查我是否登录并显示自定义内容.我在 iMac 上使用 Firefox 登录到 xyz.com.现在,当我尝试同时访问 xyz.com/page1.php 和 xyz.com/page2.php 时,直到 page1 加载 page2 才被处理.

All pages of xyz.com use sessions to check if I am logged in and display customized content. I am logged into xyz.com using Firefox on my iMac. Now, when I try to visit, xyz.com/page1.php and xyz.com/page2.php at the same time, until page1 loads page2 is not processed.

代码示例

xyz.com/contains(链接):

xyz.com/contains (links):

/* session check code here */
Page1
Page2

xyz.com/page1.php 包含:

xyz.com/page1.php contains:

/* session check code here */
echo "Hello";
flush();
sleep(5);
echo "done";

xyz.com/page2.php 包含:

xyz.com/page2.php contains:

/* session check code here */
echo "Second Page";
/* {insert code} to log time() to log.txt */

测试

这就是我所做的.我登录到 shell 并保持此命令运行:

Here's what I do. I login to shell and keep this command running:

user@xyz.com [~/public_html]# tail -f log.txt

从我的浏览器 (Firefox)(在 xyz.com 上),我在选项卡中打开了 page1 和 page2 的多个实例.如果你能看到,page1 至少需要 5 秒才能加载.现在,在加载第 1 页之前,对第 2 页的请求正在等待处理.它根本没有处理.我怎么知道?page2 末尾的代码将访问时间记录到我正在监视的文件中.让我们考虑以下情况:

From my browser (Firefox), (on xyz.com), I open multiple instances of page1 and page2 in tabs. If you can see, page1 will at least take 5 seconds to load. Now, until page 1 loads, request to page2 is pending. It's not at all processed. How do I know that? The code at the end of page2 logs access time to a file which I am monitoring. Let's consider the following case:

向(按顺序)发出的请求1. page1.php2.page2.php3.page2.php4.page1.php5.page1.php6. page2.php

Requests fired to (in order) 1. page1.php 2. page2.php 3. page2.php 4. page1.php 5. page1.php 6. page2.php

结果(大约)

1237961919 <-- #2
1237961920 <-- #3
1237961931 <-- #6

1237961919 <-- #2
1237961920 <-- #3
1237961931 <-- #6

预期(大约)

1237961915 <-- #2
1237961915 <-- #3
1237961915 <-- #6

1237961915 <-- #2
1237961915 <-- #3
1237961915 <-- #6

^假设所有调用同时被触发

^Assuming that all calls were fired at the same time

观察

在处理呼叫时,我显然也无法访问 xyz.com(这是另一个请求).但是,如果我在另一个浏览器(Safari)中打开它,它运行良好.那是因为这是另一个会话?

While the calls are being processed, I am obviously not able to visit xyz.com as well (being another request). However, if I open it in another browser (Safari), it works well. That's because it's another session?

可能的原因

  1. 服务器有一些安全措施吗?

  1. The server has some security in place?

我更像是一个编码员,但如果有人可以指点,我可以检查服务器(VPS)以查看 apache/php 是否配置错误.

I am more of a coder but if someone can give pointers, I can check the server (VPS) to see if apache/php is misconfigured.

  • 我没有正确处理会话?

  • I am not handling sessions correctly?

    有关系吗?第二个请求不应该作为不同的线程处理吗?

    Does it matter? Shouldn't the second request be processed as a different thread?

  • 外星人正在控制我的 VPS.

  • Aliens are controlling my VPS.

    好吧,开玩笑的.我只是厌倦了追踪这个问题.如果有人知道这里可能出了什么问题,我们将不胜感激.

    Ok, kidding. I am just tired of tracing this issue. Would really appreciate if anyone has any clue what could be going wrong here.

  • 推荐答案

    在完成会话检查代码后,尝试在 page1.php 中调用 session_write_close().

    Try to call session_write_close() in page1.php after you finished session check code.

    /* session check code here */
    session_write_close();
    echo "Hello";
    flush();
    

    这应该关闭会话文件(解除锁定)并且 page2.php 可以打开它.

    This should close the session file (remove the lock) and page2.php can open it.

    http://php.net/manual/en/function.session-write-close.php

    这篇关于服务器每个会话只允许一个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆