Closed Thread Icon

Preserved Topic: can someone explain the flock function to me? Pages that link to <a href="https://ozoneasylum.com/backlink?for=21127" title="Pages that link to Preserved Topic: can someone explain the flock function to me?" rel="nofollow" >Preserved Topic: can someone explain the flock function to me?\

 
Author Thread
LiKwiD
Paranoid (IV) Inmate

From: NJ
Insane since: Mar 2002

posted posted 07-15-2002 11:57

i read about it in the php manual but they dont explain it that well. can someone elaborate more please?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-15-2002 12:52

hm. not that I ever used it...
but it seems you can 'lock' other processes (and possibly other php scripts) from accessing the same file you're manipulating right now.
This can be helpful when you have multiple users accessing the same 'data' file in order to preserve it's structure. you wouldn't need it if for example you were just appending to a file.

honestly. use a sql database ;-)

hope my meager explanation helps a bit,

Tyberius Prime

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 07-15-2002 15:04

So say you are writing a counter program that increments a text file after each visit.

Now assume that 2 people hit this page at the same time. This means both execute the PHP code to get the variable and then add one to it.

You would run into 1 of 2 problems with this.

1) The data would be overwritten by the second executing script, since one would have to happen first.

2) You would have a conflict in which your microsoft server will crash, or your *nix system would disreguard one.

Either way you would lose tracking of one of the hits. So if you flock the file then the other would have to wait for it to be unlocked before it could access it. Therefore perserving the integrity of the data.

LiKwiD
Paranoid (IV) Inmate

From: NJ
Insane since: Mar 2002

posted posted 07-16-2002 00:39

aaaaaaaaaaaahah! thank you so much. now see that makes much more sense. you're the php masta warmage

Rahly
Bipolar (III) Inmate

From: Michigan
Insane since: Jul 2002

posted posted 07-18-2002 01:02

yes but remember.... flock is an ADVISORY lock... meaning programs do NOT have to use it..... so a program can modify a file that you flocked even though you have it locked..... that is why you should make all your programs use it.

Rahly

Rahly
Bipolar (III) Inmate

From: Michigan
Insane since: Jul 2002

posted posted 07-18-2002 01:04

forgot this though.... it locks the ENTIRE file.... if you do database programming like i do..... lower level.... the fcntl is a lot better... it allows you to flock just a "part" of your file... that way other programs can modify other parts

Rahly

« BackwardsOnwards »

Show Forum Drop Down Menu