By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,812 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,812 IT Pros & Developers. It's quick & easy.

flock and file access

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.