Re: [PHP] File locking problem

2002-11-08 Thread Krzysztof Dziekiewicz
 I'm having file locking problems.

 I'm using fopen() to write a file via FTP.  At the end, I'm doing...

 fflush($fp);
 fclose($fp);

 ...and then I include it immediately after.  But many times I only get part
 of what I wrote to the file, which suggests that it wasn't really flushed
 and closed properly.

Do you use include or require. In such situation you should not use
include.




-- 
Krzysztof Dziekiewicz


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




Re: [PHP] File locking problem

2002-11-08 Thread Charles Wiltgen
Krzysztof Dziekiewicz wrote...

 Do you use include or require. In such situation you should not use
 include.

I tried require() too, but it made no difference.  I later learned that if
you fopen(), write some stuff, fflush() and ffclose(), that doesn't mean the
file is complete (or that it even exists).

This has to be a PHP bug, which I'd be happy to file if someone more
experienced could confirm that it isn't stupid user error.

For a workaround, after I fflush() and fclose() I while() until the file
exists, and then while() until it's larger than 10 bytes.  I should while()
until it's the size of the data I've written, but this method has been
reliable so far.

-- 
Charles Wiltgen

   Well, once again my friend, we find that science is a two-headed beast.
One head is nice, it gives us aspirin and other modern conveniences...
but the other head of science is bad!  Oh beware the other head of
science...it bites! -- The Tick





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




Re: [PHP] File locking problem

2002-11-08 Thread Ernest E Vogelsinger
At 16:50 08.11.2002, Charles Wiltgen spoke out and said:
[snip]
I tried require() too, but it made no difference.  I later learned that if
you fopen(), write some stuff, fflush() and ffclose(), that doesn't mean the
file is complete (or that it even exists).

This has to be a PHP bug, which I'd be happy to file if someone more
experienced could confirm that it isn't stupid user error.
[snip] 

I don't believe it has something to do with PHP, much more with the FTP
server you're accessing... This might delay the actual flushing for what
reason ever. I don't believe PHP buffers files differently if they are
accessed using an fopen url wrapper.


-- 
   O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
^ http://www.vogelsinger.at/



Re: [PHP] File locking problem

2002-11-08 Thread Charles Wiltgen
Ernest E Vogelsinger wrote...

 This has to be a PHP bug, which I'd be happy to file if someone more
 experienced could confirm that it isn't stupid user error.
 
 I don't believe it has something to do with PHP, much more with the FTP server
 you're accessing... This might delay the actual flushing for what reason ever.
 I don't believe PHP buffers files differently if they are accessed using an
 fopen url wrapper.

The Linux system I'm FTPing to is using ProFTPD, which as I understand it is
one of the best open-source servers out there.

I will add a note to the documentation along the lines of If you fopen() to
an FTP URI, write some stuff, fflush() and ffclose(), that doesn't mean the
file is complete (or that it even exists).  Check for both of these things
before you do anything with the file.

Thanks!

-- Charles Wiltgen


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




Re: [PHP] File locking problem

2002-11-07 Thread Charles Wiltgen
Charles Wiltgen wrote...

 I'm having file locking problems.
 
 I'm using fopen() to write a file via FTP.  At the end, I'm doing...
 
   fflush($fp);
   fclose($fp);
 
 ...and then I include it immediately after.  But many times I only get part
 of what I wrote to the file, which suggests that it wasn't really flushed
 and closed properly.

BTW, when I only get part of the file in the browser, I open it with Pico
and it's all there.  So I know that $stuff = ob_end_clean() is working, and
that $stuff is being written to the fopen(ftp://...) pointer correctly.

I suspect that PHP is including before the file is closed, but not returning
an error.  I haven't found any other mechanisms in PHP that would allow me
to verify that the file is really, really, really closed after using
fflush() and fclose() on an fopen(ftp://...;).  Any ideas?

-- Charles Wiltgen


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




Re: [PHP] File locking problem

2002-11-07 Thread Marco Tabini
Charles,

2 questions--

1) What OS are you using?
2) Does the file include PHP code? Otherwise, can you keep its contents
in a string and simply output that string? If it contains PHP code, are
you sure that there aren't any errors in the PHP code?

Ok, so it was a bit more than 2 questions :-)


Marco
-- 

php|architect - The magazine for PHP Professionals
The first monthly worldwide  magazine dedicated to PHP programmer

Come visit us at http://www.phparch.com!


---BeginMessage---
Charles Wiltgen wrote...

 I'm having file locking problems.
 
 I'm using fopen() to write a file via FTP.  At the end, I'm doing...
 
   fflush($fp);
   fclose($fp);
 
 ...and then I include it immediately after.  But many times I only get part
 of what I wrote to the file, which suggests that it wasn't really flushed
 and closed properly.

BTW, when I only get part of the file in the browser, I open it with Pico
and it's all there.  So I know that $stuff = ob_end_clean() is working, and
that $stuff is being written to the fopen(ftp://...) pointer correctly.

I suspect that PHP is including before the file is closed, but not returning
an error.  I haven't found any other mechanisms in PHP that would allow me
to verify that the file is really, really, really closed after using
fflush() and fclose() on an fopen(ftp://...;).  Any ideas?

-- Charles Wiltgen


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



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


Re: [PHP] File locking problem

2002-11-07 Thread Charles Wiltgen
Marco Tabini wrote...

 1) What OS are you using?

Linux.

 2) Does the file include PHP code?

Yes.

 If it contains PHP code, are you sure that there aren't any errors in the PHP
 code?

Yes.  The resulting XHTML validates when the include works (more than half
the time).  The rest of the time, the file is being created correctly but
not included correctly.

I've tried to include() and require().  No error is ever generated, I
suspect because the file exists, and include/require are being called while
the file is still open (even though I've flushed and closed it).  Shoot.

-- Charles Wiltgen


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




Re: [PHP] File locking problem

2002-11-07 Thread Marco Tabini
Ok, here's another possibly stupid solution. Have you tried (a) setting
a pause (like 2 secs) between when you end writing and include the file
or (b) writing the file, then refreshing the page with a parameter and
including it only then? In the latter case, terminating the script and
refreshing it might cause the o/s to properly flush the file buffers.

Just a couple of thoughts. Hope this helps.


Marco
-
php|architect -- The Monthly Magazine For PHP Professionals
Come visit us on the web at http://www.phparch.com!

On Thu, 2002-11-07 at 17:58, Charles Wiltgen wrote:
 Marco Tabini wrote...
 
  1) What OS are you using?
 
 Linux.
 
  2) Does the file include PHP code?
 
 Yes.
 
  If it contains PHP code, are you sure that there aren't any errors in the PHP
  code?
 
 Yes.  The resulting XHTML validates when the include works (more than half
 the time).  The rest of the time, the file is being created correctly but
 not included correctly.
 
 I've tried to include() and require().  No error is ever generated, I
 suspect because the file exists, and include/require are being called while
 the file is still open (even though I've flushed and closed it).  Shoot.
 
 -- Charles Wiltgen
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



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




Re: [PHP] File locking problem

2002-11-07 Thread Charles Wiltgen
Marco Tabini wrote...

 Ok, here's another possibly stupid solution.

Not at all.  My solution was not far from that -- I have to wait for the
file to exist, and then to have something in it, and then include it.  (See
my PHP fopen() bug + solution post.)

Thank you,

-- Charles Wiltgen


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




Re: [PHP] File locking problem

2002-11-06 Thread Marco Tabini
Just a (possibly stupid) suggestion--is it possible that the file is
being overwritten by another instance of your script that's run in the
meantime?

-
php|architect -- The Magazine for PHP Professionals
Check us out on the web at http://www.phparch.com

On Wed, 2002-11-06 at 23:06, Charles Wiltgen wrote:
 Hello,
 
 I'm having file locking problems.
 
 I'm using fopen() to write a file via FTP.  At the end, I'm doing...
 
 fflush($fp);
 fclose($fp);
 
 ...and then I include it immediately after.  But many times I only get part
 of what I wrote to the file, which suggests that it wasn't really flushed
 and closed properly.
 
 What else can I do?
 
 Thanks,
 
 -- 
 Charles Wiltgen
 
Well, once again my friend, we find that science is a two-headed beast.
 One head is nice, it gives us aspirin and other modern conveniences...
 but the other head of science is bad!  Oh beware the other head of
 science...it bites! -- The Tick
 
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



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




Re: [PHP] File locking problem

2002-11-06 Thread Charles Wiltgen
Marco Tabini wrote...

 Just a (possibly stupid) suggestion--is it possible that the file is being
 overwritten by another instance of your script that's run in the meantime?

This may also be a problem at some point, but currently I'm just trying to
get it working in an test environment where only one instance is running.

I know I can just use another empty file as a semaphore, but my performance
is already killed by having to use FTP to create and delete files with PHP,
and I need to do whatever I can do avoid it.

Basically, it appears that using fflush() and fclose() is no guarantee that
a file is completely written, and I'm wondering what I can do besides insert
sleep() statements.

-- 
Charles Wiltgen

  Love is a snowmobile racing across the tundra and
   then suddenly it flips over, pinning you underneath.
   At night, the ice weasels come. - Nietzsche (Groening)
 



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