One quick glance of an experienced eye allowed to understand the blurred
and almost unreadable
wr******@charter.net's handwriting:
I've got a PHP program that I've added flock() to in order to protect
multiple scripts trying to write to the same file. After I added the
flock() to the code the performance of the code went way down. Can
anyone tell me if calling flock() on a file handle is particularly
slow?
Dunno about the performance of the flock() function by itself, but be
sure to check whether there is no other script (or maybe a second
invocation of this script?) that locks the file and causes your script
to wait for an unlock.
What I mean is: you have a script "a.php", which locks the file, writes
to it, and unlocks it. Now imagine a few surfers visit your page one
right after the other. What happens is:
1). Surfer 1 visits your page, a.php locks the file, starts writing;
2). Surfer 2 visits your page, a.php cannot write to the file, waits;
3). Surfer 3 visits your page, same as above.
When 1). finishes to write and unlocks, 2). locks and writes and 3).
still waits. Now, the queue can get really long and the time to wait can
get really huge when you start to get ~20 visits and it will be getting
worse.
Cheers
Mike