How to get to know if file is currently being written by another app?
How to get to know if file is currently being written by another app?
am 10.11.2007 16:46:47 von alexandis
I run some remote binary with php script in background. The binary
creates some big files - a lot of files, they are being written 2
days, one after another, by chunks.
I output window where I display a list of these files by another php
script. I must show only those of them that are COMPLETELY DONE. How
can I do this?
I don't have access to binary sources.
OS is Solaris.
Re: How to get to know if file is currently being written by anotherapp?
am 10.11.2007 17:27:36 von zdzisio
alexandis@gmail.com pisze:
> I run some remote binary with php script in background. The binary
> creates some big files - a lot of files, they are being written 2
> days, one after another, by chunks.
>
> I output window where I display a list of these files by another php
> script. I must show only those of them that are COMPLETELY DONE. How
> can I do this?
>
> I don't have access to binary sources.
>
> OS is Solaris.
>
lsof |grep $filename
z.
Re: How to get to know if file is currently being written by another app?
am 11.11.2007 10:47:40 von alexandis
it's some external util, there's no such available from command
line... should i ask admin to install it on Solaris?
Re: How to get to know if file is currently being written by another app?
am 11.11.2007 21:17:18 von Aaron Saray
On Nov 10, 9:46 am, alexan...@gmail.com wrote:
> I run some remote binary with php script in background. The binary
> creates some big files - a lot of files, they are being written 2
> days, one after another, by chunks.
>
> I output window where I display a list of these files by another php
> script. I must show only those of them that are COMPLETELY DONE. How
> can I do this?
>
> I don't have access to binary sources.
>
> OS is Solaris.
What if you checked out the 'flock' functions of PHP? You might be
able to lock the file, then check to see if they're locked by the
other script... etc.
Re: How to get to know if file is currently being written by another app?
am 13.11.2007 18:01:05 von Saul
In article <1194812238.516514.122610@k79g2000hse.googlegroups.com>,
102degrees@102degrees.com says...
> On Nov 10, 9:46 am, alexan...@gmail.com wrote:
> > I run some remote binary with php script in background. The binary
> > creates some big files - a lot of files, they are being written 2
> > days, one after another, by chunks.
> >
> > I output window where I display a list of these files by another php
> > script. I must show only those of them that are COMPLETELY DONE. How
> > can I do this?
> >
> > I don't have access to binary sources.
> >
> > OS is Solaris.
>
> What if you checked out the 'flock' functions of PHP? You might be
> able to lock the file, then check to see if they're locked by the
> other script... etc.
>
>
Didnt I read somewhere that flock is unreliable?
Any info on that would be appreciated.
saul
Re: How to get to know if file is currently being written by another app?
am 13.11.2007 20:01:02 von nc
On Nov 13, 9:01 am, saul wrote:
> In article <1194812238.516514.122...@k79g2000hse.googlegroups.com>,
> 102degr...@102degrees.com says...
>
>
> > What if you checked out the 'flock' functions of PHP? You might be
> > able to lock the file, then check to see if they're locked by the
> > other script... etc.
>
> Didnt I read somewhere that flock is unreliable?
In threaded environments (which usually means Windows)
> Any info on that would be appreciated.
http://www.php.net/flock
Cheers,
NC
Re: How to get to know if file is currently being written by another app?
am 14.11.2007 15:08:14 von alexandis
Flock doesn't fit me. Flock is used to make lock FROM WITHIN php
script.
And in my case I have external binaries, that create some output
files, writing them piece by piece.
And what i need to do is to CHECK if some file in filesystem is being
written in the moment or not.
The only approach i can see is to check modification date of the file
and if file has not been modified quite a while - suppose that it's
already done. But this approach is not reliable... :(
Re: How to get to know if file is currently being written by another app?
am 14.11.2007 17:15:26 von nc
On Nov 14, 6:08 am, alexan...@gmail.com wrote:
>
> Flock doesn't fit me. Flock is used to make lock
> FROM WITHIN php script.
Indeed. So if a PHP script can obtain an exclusive (writer's) lock on
a file, it means that no other process has that lock, meaning that the
file is not open for writing at the moment...
Cheers,
NC
Re: How to get to know if file is currently being written by another app?
am 14.11.2007 19:20:33 von alexandis
Wow, if things are like that - I will give it a try... Thanks.
Re: How to get to know if file is currently being written by another app?
am 14.11.2007 21:55:01 von alexandis
i tried to open file in write mode and oops! now it's zero... maybe i
should have used w+... :(
Is it correct and safe like following?
if ($handle = opendir($sourcefile_dir)) {
while (false !== ($filename = readdir($handle))) {
if ($filename != "." && $filename != ".." && is_file($sourcefile_dir.
$filename)) {
$fp = fopen($sourcefile_dir.$filename, "w+");
if (flock($fp, LOCK_EX)) {
?>
Outputting file info
flock($fp, LOCK_UN);
}
fclose($fp);
}
}
closedir($handle);
}
?>
Re: How to get to know if file is currently being written by another app?
am 14.11.2007 22:52:11 von alexandis
damned, no! again zero! But i even didn't start to write into file!
SO i should open it as for reading?
Re: How to get to know if file is currently being written by another app?
am 15.11.2007 02:07:02 von gordonb.t6a5d
>> Flock doesn't fit me. Flock is used to make lock
>> FROM WITHIN php script.
>
>Indeed. So if a PHP script can obtain an exclusive (writer's) lock on
>a file, it means that no other process has that lock, meaning that the
>file is not open for writing at the moment...
flock() is advisory, meaning that it won't stop someone else from
reading or writing, unless that someone else is obtaining locks
before doing the reading or writing. *Mandatory* locking has great
potential for evil (e.g. lock some critical system files, then go
to sleep indefinitely, and anyone trying to log in ends up waiting
for you to let go of the locks).
Re: How to get to know if file is currently being written by another
am 15.11.2007 23:45:33 von nc
On Nov 14, 12:55 pm, alexan...@gmail.com wrote:
>
> i tried to open file in write mode and oops!
> now it's zero... maybe i should have used w+... :(
Nope; "a"...
Cheers,
NC