问题
My server is running CentOS under Plesk so editing my httpd.conf to add a Rewritelock entry is not an option as I understand it. A RewriteLock entry is also not allowed in a vhost.config either, so I think I'm stuck looking at an alternative as decribed here.
As a test I am successfully using this approach, which is slightly modified since my entries are in my vhost.conf. I also added my attempt at locking the file:
#!/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";
}
}
?>
As discussed here, it appears any process will wait for an exclusive lock, but I'm not sure how best to test. For those of you who may know, will my use of flock() ensure that all processes will wait and no requests will get scrambled in this ever running program?
回答1:
There is no need to edit main httpd.conf. Plesk allows to define custom apache directives can in separate config file:
/var/www/vhosts/domain.com/conf/vhost.conf
And then need to update domain's configuration:
For Plesk 10 and Plesk 11:
/usr/local/psa/admin/bin/httpdmng --reconfigure-domain domain.com
For Plesk 7, 8 and 9:
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com
来源:https://stackoverflow.com/questions/16386974/apache-rewritelock-alternative-using-php