RE: How to make sure that the target file to read is not under writing by others?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----Original Message-----
From: Ashley Sheridan [mailto:ash@xxxxxxxxxxxxxxxxxxxx] 
Sent: 19 August 2009 03:34 PM
To: arno@xxxxxxxxxxxxxx
Cc: 'Dengxule'; 'Php Maillist'
Subject: RE:  How to make sure that the target file to read is not
under writing by others?

On Wed, 2009-08-19 at 15:31 +0200, Arno Kuhl wrote:
> (any computer would instantly crash if that sort of basic housekeeping 
> wasn't done)

No, it really wouldn't! If it did, then you'd never have video playing
software out there that supported broken downloads, no preview software for
semi-downloaded items. Have you ever been sent a large jpeg over a slow
connection on a messenger program? You can open the file way before it's
finished downloading and actually see it progressively load in.

Thanks,
Ash
http://www.ashleysheridan.co.uk

-------

If anyone was left a bit unsure about whether or not a write command in PHP
could result in a file on a local filesystem being left in a semi-written
state (i.e. some other script started reading the file while your script had
only written part of its output string) rest assured that fwrite() always
writes *all* the contents to the file without the need of flock(), by the
time any other process (whether PHP or not) reads that file (assuming you're
not writing megabytes of data with a single fwrite()). To quote the PHP
manual:

"If handle was fopen()ed in append mode, fwrite()s are atomic (unless the
size of string exceeds the filesystem's block size, on some platforms, and
as long as the file is on a local filesystem). That is, there is no need to
flock() a resource before calling fwrite(); all of the data will be written
without interruption."

Cheers
Arno


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux