Apache同源请求阻塞

发布于 2024-12-13 05:17:58 字数 240 浏览 0 评论 0原文

当我尝试在同一浏览器的不同选项卡中从服务器加载两个相同页面时,它会等待一个页面完成,然后再启动另一个页面。这很好,但我有一个 cron 进程,需要对同一脚本进行多次调用,并且我不能有这种类型的阻塞行为。我认为这是因为该进程与服务器具有相同的会话/连接,并且默认行为是一次只允许来自同一源的一个请求......我该如何解决这个问题?我想要做的是让 cron 进程能够触发对我的脚本之一的调用,并且 apache 启动目标脚本的一个新实例来处理每个脚本的请求。这可能吗?

When I try to load two of the same page from my server in different tabs of the same browser, it waits for one to finish before starting the other. This is fine but I have a cron process which needs to call several calls to the same script and I can't have this type of blocking behavior. I think it is because the process has the same session/connection with the server and the default behavior is to only allow one request at a time from the same source... how can I get around this? What I want to be able to do is have a cron process be able to fire off calls to one of my scripts and apache spin up a new instance of the targeted script to handle the request for each one. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜无邪 2024-12-20 05:17:58

您是否使用 PHP 标准的基于文件的会话?当您执行 session_start() 时,PHP 会锁定会话,并保持文件锁定,直到脚本退出,或者您执行 session_write_close()

这具有防止提供任何其他启用会话的页面的效果,因为在解除锁定之前它们无法访问会话文件。

session_write_close() 可以在脚本中的任何位置调用。它所做的只是按当时的情况写出 _SESSION 数组,但使该数组可供读取。如果需要进行任何修改,您可以随时在脚本上重新打开会话。

基本上,你会有

<?php

session_start(); // populate $_SESSION;
session_write_close(); // relinquish session lock

.... dome some really heavy duty long computations

session_start();
$_SESSION['somekey'] = $new_val;

Are you using PHP's standard file-based sessions? PHP locks the session when you do a session_start() and keeps the file locked until the script exits, or you do a session_write_close().

This has the effect of preventing any OTHER session-enabled pages from being served up, as they can't get at the session file until the lock is removed.

session_write_close() can be called at any point in the script. All it does is write out the _SESSION array as it is at that moment, but leaves the array available for reading. You can always re-open the session later on the script if you need to make any modifications.

Basically, you'd have

<?php

session_start(); // populate $_SESSION;
session_write_close(); // relinquish session lock

.... dome some really heavy duty long computations

session_start();
$_SESSION['somekey'] = $new_val;
空城旧梦 2024-12-20 05:17:58

我不认为 php continue 有任何问题,事实上我喜欢它的行为

Use continue 2;因为 continue 与 switch 中的brake 的作用相同,并且 for、while、foreach 等循环在离开 switch 后将继续其进程。

下面的示例将仅回显 1,因为我正在中断 switch 和 foreach 的继续。

$un_array=array(1,2);

foreach($un_array as $num)
{
    switch($num)
    {
        case 1:
        //nothing
        break;
        case 2:
            continue 2;
        break;
    }

    echo $num;

}

exit;

I don't think that there is any problem with php continue, in fact I like how it behaves

Use continue 2; because continue will do the same as brake in the switch and the for, while, foreach, etc. loops will continue their course after coming out of the switch.

The following example will echo only 1, because I am breaking from the switch and the continuing of the foreach.

$un_array=array(1,2);

foreach($un_array as $num)
{
    switch($num)
    {
        case 1:
        //nothing
        break;
        case 2:
            continue 2;
        break;
    }

    echo $num;

}

exit;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文