473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

can't understand flock()

I've scoured over manual page for flock on http://in2.php.net/flock but
I can't understand a few things:

1. will flock wait until a different process releases the lock ?
2. please clarify this line:

" If you don't want flock() to block while locking, add LOCK_NB "

what does "block" mean above?

I'd like to use flock() in a manner that when locking attempt fails on
a file (maybe it is alreadly locked by some other process) then the
script wouldn't wait but go on and do something, eg: close the file.

Thanks
Mike

Jul 17 '05 #1
3 2794
>I've scoured over manual page for flock on http://in2.php.net/flock but
I can't understand a few things:

1. will flock wait until a different process releases the lock ?
Yes, in blocking mode.
No, in non-blocking mode.
2. please clarify this line:

" If you don't want flock() to block while locking, add LOCK_NB "

what does "block" mean above?
Wait for someone to let go of the lock, if necessary.
In pathological cases, this could take years.
I'd like to use flock() in a manner that when locking attempt fails on
a file (maybe it is alreadly locked by some other process) then the
script wouldn't wait but go on and do something, eg: close the file.


Then you want non-blocking mode.

Gordon L. Burditt
Jul 17 '05 #2
Got it, but EWOULDBLOCK is still confusing.. Any explanation?

Jul 17 '05 #3
>Got it, but EWOULDBLOCK is still confusing.. Any explanation?

EWOULDBLOCK means the call to flock() would have blocked, but you
asked for non-blocking mode, so it's going to immediately return
an error instead. In other words, you didn't get the lock: someone
else has it.

Gordon L. Burditt
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniel Brunthaler | last post by:
hi, i've a problem with file locking. seems that flock() and gzopen() do not work together. i get the error (or warning) message ... Warning: flock(): cannot represent a stream of type ZLIB...
14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
18
by: Dino | last post by:
dear all, i've created an application for a customer where the customer can upload ..csv-files into a specified ftp-directory. on the server, a php-script, triggered by a cronjob, reads all the...
3
by: Rex Karz | last post by:
Newbie here. I interpret the fine print at http://us2.php.net/manual/en/function.flock.php to mean that flock() does not work where the file being locked is on an NFS filesystem. The...
3
by: thakadu | last post by:
The following code works as expected when run in the main body of a python script (ver 2.3.5) on OpenBSD v3.8. but when it is in the body of a function definition it does not work. It does not...
7
by: sven.holcombe | last post by:
Hi there, I'm trying to just prevent multiple instances of a script running. I would have thought that the following code would do this for me. <php $fp = fopen("foo.txt", "w"); flock($fp,...
4
by: Time Waster | last post by:
Is this a stupid use of flock: FILE *fp=fopen(SOME_FILE_CONSTANT,"r+"); flock(fileno(fp),LOCK_EX); something important here, including reads and a write to fp flock(fileno(fp),LOCK_UN);...
2
by: xucs007 | last post by:
I ran following 2 programs (lock1, lock2) at almost same time, to write either "123456", or "222" to file "aaa" at the same time. But I often just got "222456" in "aaa" . Is this a bug of python...
6
by: Bill H | last post by:
I am wondering if this is possible. I have a file that is accessed by multiple users and keeps track of activity (the file is polled by flash every 2 seconds). As users leave, the flash program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.