【问题标题】:Apache RewriteLock alternative using PHP?使用 PHP 的 Apache RewriteLock 替代方案?
【发布时间】:2013-05-05 17:09:06
【问题描述】:

我的服务器在 Plesk 下运行 CentOS,因此编辑我的 httpd.conf 以添加 Rewritelock 条目不是我理解的选项。在 vhost.config 中也不允许 RewriteLock 条目,所以我想我一直在寻找替代方案,如here 所述。

作为测试,我成功地使用了this 方法,由于我的条目在我的 vhost.conf 中,因此稍作修改。我还添加了锁定文件的尝试:

#!/usr/bin/env php
<?php
/* Extra lines to add to vhost.conf:
RewriteEngine On
RewriteMap tryme prg:/home/trainee/website/andy
RewriteRule (.*\.htm) ${tryme:$1}
*/

set_time_limit(0); # forever program!
$keyboard = fopen("php://stdin","r");
flock($keyboard, LOCK_EX); //lock the file
while (1) {
        $line = trim(fgets($keyboard));
        if (preg_match('/^(.*)\.htm$/',$line,$igot)) {
                print "$igot[1].html\n";
        } else {
                print "$line\n";
        }
}
?>

正如here 所讨论的,似乎任何进程都会等待排他锁,但我不确定如何最好地进行测试。对于那些可能知道的人,我使用flock() 是否会确保所有进程都将等待并且在这个一直运行的程序中没有请求会被打乱?

【问题讨论】:

    标签: php apache plesk flock


    【解决方案1】:

    无需编辑主 httpd.conf。 Plesk 允许在单独的配置文件中定义自定义 apache 指令:

    /var/www/vhosts/domain.com/conf/vhost.conf
    

    然后需要更新域的配置:

    对于 Plesk 10 和 Plesk 11:

    /usr/local/psa/admin/bin/httpdmng --reconfigure-domain domain.com
    

    对于 Plesk 7、8 和 9:

    /usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com
    

    【讨论】:

    • vhost.conf 文件中不允许重写锁定条目。
    猜你喜欢
    • 2011-10-03
    • 2014-12-27
    • 1970-01-01
    • 2011-06-20
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多