|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
it's some external util, there's no such available from command
line... should i ask admin to install it on Solaris? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Nov 13, 9:01 am, saul <s...@dummy.com> 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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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... ![]() |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
Wow, if things are like that - I will give it a try... Thanks.
|
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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); } ?> |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
damned, no! again zero! But i even didn't start to write into file!
SO i should open it as for reading? |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
>> 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). |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
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... ![]() |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
alexandis@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. jstucklex@attglobal.net ================== |
|
![]() |
| Outils de la discussion | |
|
|