note 111985 deleted from function.flock by mazzanet
| From: | mazzanet@php.net | Date: | Fri, 19 Apr 2013 05:03:44 +0000 |
| Subject: | note 111985 deleted from function.flock by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194557@lists.php.net to get a copy of this message | ||
Note Submitter: metamarkers at gmail dot com
----
you should not be creating "clever workarounds" to circumvent expected locking behavior.
if some external process or library doesn't honor advisory locks then simply don't use it.
instead of using lock files, consider opening a file for reading and getting an exclusive lock on
the handle, then open a new handle for writing without obtaining a second lock. if you find yourself
doing gymnastics in order to "get an answer without asking a question" then there's
something wrong with your overall system and you're only going to dig yourself deeper into that
hole.
furthermore, don't put the thing that calls flock in a loop to "make sure its
locked". your process is not the only one running on a system, and this is what's known as
a "busy-waiting" antipattern and is well documented. you must learn to interact with the
operating system as it expects you to and accept and work around failures. a simple message like
"sorry, can't process your request at this time due to heavy server load. try again later.
here's some pictures of cats." is an acceptable message for a user to see. not expecting
and accepting failures is a failure in and of itself.