473,800 Members | 2,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5083
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************ **********@k79g 2000hse.googleg roups.com>,
10********@102d egrees.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.com wrote:
In article <1194812238.516 514.122...@k79g 2000hse.googleg roups.com>,
102degr...@102d egrees.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($source file_dir)) {
while (false !== ($filename = readdir($handle ))) {
if ($filename != "." && $filename != ".." && is_file($source file_dir.
$filename)) {
$fp = fopen($sourcefi le_dir.$filenam e, "w+");
if (flock($fp, LOCK_EX)) {
?>
Outputting file info
<?php
flock($fp, LOCK_UN);
}
fclose($fp);
}
}
closedir($handl e);
}
?>

Nov 14 '07 #10

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

Similar topics

6
2788
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 multiple entries to the file, and then rename it and copy it to a new location when the file reaches a certian size, or a certain time span elapses (which ever comes first). I have created a static/shared timer member variable in class that writes...
2
933
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 have used Regasm and registered the assembly in the registry with CODEBASE option. eg: regasm myDll.dll /tlb:myDll.tlb /codebase
1
2871
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 seperate file in a specific directory, but instead 'integrate' it in my application? Thanks peter
9
6529
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 downloaded it, and was attempting to use (where FILENAME = the .xml and sSchema is the path+filename.xsd): public void ReadXml(string sSchema) {
4
12461
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
1864
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 imported into an automation system. The problem that I am having is telling if IIS (FTP) is done uploading the file and it is no longer in use. Currently, the software just checks the file time. If the time is older than 5 minutes, the software...
3
1087
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 contents and depending what they are I move it! however I'm getting error when I'm am reading the file before its is fully written ( the writing is slow as its over a WAN!) so I want to loop until the file is fully created/ written.
4
1586
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 the front end to render out site's navigation, site map, breadcrumbs, etc. We're using it because it's more efficient to just cache the XML file rather than doing recursive DB calls on each page load. We ran into a problem where, as far as we...
3
4133
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 all the files. /// </summary> /// <param name="di">Directory Info Object</param> /// <param name="searchPattern">Search Pattern (*.pdf)</param> /// <param name="MyFiles">referenced array list</param>
0
9691
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10255
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.