473,396 Members | 1,933 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.

flock and file access

Hello, I am making the not so smooth transition from Perl to PHP and my
question concerns file locking. PHP has a myriad of file parsing
functions an many do not appear do give access to a file handle for
flock, i.e., file(), parse_ini_file()...convenient since they dump into
an array, I have data in TSV (tab separated value) files. Do the
functions other than fopen() use some internal locking? Even on reading,
good practice to flock LOCK_SH. Been referencing manual and 'cuckoo'
book but haven't found the answer. Thank you.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jul 17 '05 #1
3 1727
Jonathan.
Hello, I am making the not so smooth transition from Perl to PHP and my
question concerns file locking. PHP has a myriad of file parsing
functions an many do not appear do give access to a file handle for
flock, i.e., file(), parse_ini_file()...convenient since they dump into
an array, I have data in TSV (tab separated value) files. Do the
functions other than fopen() use some internal locking? Even on reading,
good practice to flock LOCK_SH. Been referencing manual and 'cuckoo'
book but haven't found the answer. Thank you.


As you said functions are only fopen. Although there is
file_get_contents that is exactly like fopen except that it reads all of
the file contents into a variable.

Mike
Jul 17 '05 #2
Mike Willbanks wrote:
<snip>
As you said functions are only fopen. Although there is
file_get_contents that is exactly like fopen except that it reads all of
the file contents into a variable.

Mike


file_get_contents() as many other file functions I did not mention but
are handy, but do not seem to have any way to perform file locking. I am
trying to understand if this is so or do the functions do it internally
hidden from the user? Files accessed even just for reading in a
multitasking or network environment (like the internet) should employ
some type of file lock to prevent corruption if it is being written to
at the same time as it is being access by another instance. Books,
tutorials, and examples seem to ignore this. Is the only really correct
way is via file() where you have a file handle to specially call
flock()? That is my question.

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Jul 17 '05 #3
Jonathan,

Yes you need a file handle. I am unsure that if the other functions
have it in there. You will have to investigate the source code as no
one has really put anything anywhere.

For me I have never had to use file locking because it just simply was
not needed in the items I was working on.

Mike
file_get_contents() as many other file functions I did not mention but
are handy, but do not seem to have any way to perform file locking. I am
trying to understand if this is so or do the functions do it internally
hidden from the user? Files accessed even just for reading in a
multitasking or network environment (like the internet) should employ
some type of file lock to prevent corruption if it is being written to
at the same time as it is being access by another instance. Books,
tutorials, and examples seem to ignore this. Is the only really correct
way is via file() where you have a file handle to specially call
flock()? That is my question.

Jul 17 '05 #4

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

Similar topics

0
by: Marc | last post by:
Hello, when using flock() I get a permission denied error: Warning: fopen("<filename>", "r+") - Permission denied in <pathtofile> on line 7 I do this: $fileToOpen=substr($PHP_SELF,...
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...
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...
4
by: writeson | last post by:
Hi all, 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...
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...
1
by: Seb | last post by:
I'm trying to implement a file server using the code below. However the locking doesn't work. I can delete while put'ing a file. Anyone got an idea about why? best regards, seb
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
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.