Apache RewriteLock alternative using PHP?


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 <a href="https://stackoverflow.com/questions/10883176/rewritelock-hangs-apache-on-re-start-when-added-to-an-otherwise-working-rewrite/12733217#12733217" rel="nofollow">here</a>.

As a test I am successfully using <a href="http://www.wellho.net/resources/ex.php4?item=a603/andy" rel="nofollow">this</a> 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 <a href="http://www.php.net/manual/en/function.flock.php#95257" rel="nofollow">here</a>, 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?


There is no need to edit main httpd.conf. Plesk allows to define custom apache directives can in separate config file:


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


  • How to Execute threads in parallel and insert corresponding data in sqlite database without database
  • HBase REST API Locking Rows
  • Maintaining unique objects for names with concurrent delete
  • cannot load gems in test environment
  • When is locking on types a good idea?
  • How can I selectively modify the src attributes of script tags in an HTML document using Perl?
  • Rails 4.1 environment variables not reloading
  • How to use ResourceDictionary in Windows Phone class library project
  • How to create a custom Powershell operator?
  • php show all images in directory and sort by last modified
  • EF 4.1 DBContext AutoDetectChangesEnabled
  • Write output of for loop to multiple files
  • How can I get the choice “H2” back in the H2 consol?
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • How do I shift the decimal place in Python?
  • nodemcu custom firmware build problems
  • Android Studio Can't Find tools.jar
  • Convert SQLite database to XML
  • cygwin cannot exec 'git-add--interactive' permission denied
  • Eclipse CDT error: Unable to compile
  • error importing numpy
  • How to define and use opencv mat of user type
  • Django: Count of Group Elements
  • How to get a value (ex: baseURL) in every Karate feature?
  • Cassandra Data Model
  • Upload files with Ajax and Jquery
  • Do I've to free mysql result after storing it?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • A cron job substitute?
  • json Serialization in asp
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • Getting Messege Twice Using IMvxMessenger
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • Python/Django TangoWithDjango Models and Databases
  • java string with new operator and a literal