【发布时间】: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() 是否会确保所有进程都将等待并且在这个一直运行的程序中没有请求会被打乱?
【问题讨论】: