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

How to get to know if file is currently being written by another app?

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.

Nov 10 '07 #1
14 5036
al*******@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.
Nov 10 '07 #2
it's some external util, there's no such available from command
line... should i ask admin to install it on Solaris?

Nov 11 '07 #3
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.

Nov 11 '07 #4
In article <11**********************@k79g2000hse.googlegroups .com>,
10********@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
Nov 13 '07 #5
NC
On Nov 13, 9:01 am, saul <s...@dummy.comwrote:
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

Nov 13 '07 #6
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... :(

Nov 14 '07 #7
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

Nov 14 '07 #8
Wow, if things are like that - I will give it a try... Thanks.

Nov 14 '07 #9
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
<?php
flock($fp, LOCK_UN);
}
fclose($fp);
}
}
closedir($handle);
}
?>

Nov 14 '07 #10
damned, no! again zero! But i even didn't start to write into file!
SO i should open it as for reading?

Nov 14 '07 #11
>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).

Nov 15 '07 #12
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
Nov 15 '07 #13
I now had chance to check this.
At least the following DIDN'T WORK - even being-written files were
shown:

while (false !== ($filename = readdir($handle))) {
if ($filename != "." && $filename != "..") {
$fp = fopen($resultsourcefile_dir.$filename, "a
+");
if (flock($fp, LOCK_EX)) {
flock($fp, LOCK_UN);
//display the file
}
}
}

p.s. I had to use "a+", not "a", because I also read from the file
inside the loop. But if it doesn't matter, right? Maybe it's just a
matter of OS... :(
Dec 8 '07 #14
al*******@gmail.com wrote:
I now had chance to check this.
At least the following DIDN'T WORK - even being-written files were
shown:

while (false !== ($filename = readdir($handle))) {
if ($filename != "." && $filename != "..") {
$fp = fopen($resultsourcefile_dir.$filename, "a
+");
if (flock($fp, LOCK_EX)) {
flock($fp, LOCK_UN);
//display the file
}
}
}

p.s. I had to use "a+", not "a", because I also read from the file
inside the loop. But if it doesn't matter, right? Maybe it's just a
matter of OS... :(
This will work if the other application also uses flock(). But if it
doesn't, there isn't any real way you can tell.

The bottom line is - if the other application doesn't "play nice",
there's not much your application can do.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Dec 9 '07 #15

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

Similar topics

6
by: Dan Kelley | last post by:
We have a multithreaded app that responds to events, and writes these events to a text file. This text file is used by an external system for further processing. We want to be able to write...
2
by: Suresh Gladstone | last post by:
Hi, This is a bit with versioning and installation of the .NET dlls. I want to perform the following, 1. A third party application will be invoking my .NET dll through COM interop . For this I...
1
by: Peter Schmitz | last post by:
Hi, I'm just trying to play a *.wav file, making use of the unmanaged function "sndPlaySoundA" in winmm.dll, but I still got one question: How can I avoid, that the sound file itself has to be...
9
by: Eskimo | last post by:
I get "The attribute targetNamespace does not match the designated namespace URI" and nothing else. I have an xml file, that was pre-existing. I have to validate against the schema provided, I...
4
by: hype | last post by:
Hi, How can I find out how much space has been used in the log file and how much of it is free or yet to be used ? Thanks, Hype
3
by: Joe Kimbler | last post by:
I'm writing a "Hot Directory" software package that watches for an MP3 file to be uploaded to an FTP directory. When the file has completed uploading, it will be converted into a WAV file and...
3
by: Adrian | last post by:
Hi, Before I open a file to read it etc how can I test to ensure it not currently in use by another process? the scenario is that I'm watch for a file to be created once it is I read its...
4
by: darrel | last post by:
I've been dealing with a file locking issue for a while. Our CMS spits out a new XML file each time an item in the DB is updated. This XML file is basically our site menu, and is what we use on...
3
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
hey, got a method here (that I took from somewhere) that gets a list of all the files in a folder., /// <summary> /// Method that gets all the files in a directory and returns an arraylist of...
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
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
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
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.