Hi, Im hoping someone can help me with a small problem im having. I have a program which is logging actions from a windows application. This application puts actions into a text file which im reading and formatting to put into a database. All that is working fine. But! When reading the log file with PHP if the program wants to add an action to that log file it says it cant create the log file, obviously because im reading it with php at that time. Is there anyway I can read it but also allow the application to write to it no matter what. I can open the log file in notepad and the application will strill write to it. Thanks for any help. Martin
Well my thread explains that I am already reading the file, I do know how to read files with PHP. My problem is reading it WITHOUT stopping the program from writign to it.
I've tried copying then reading, has the same problem. How would "w+" help? Im wanting to read it. I have no control over how the windows application writes to the file. At the moment im using: $log_location = "path to file"; $handle = fopen( $log_location, "r" ); $contents = fread( $handle, filesize( $filename ) ); fclose( $handle ); PHP: Cheers
File locking in windows is pretty tedious, in *nix operating systems everything revolves around the system call flock. I know PHP has a function named the same - I have no idea how they have implemented it on windows (if they actually have). Maybe you could try something like this: (untested) <?php $log_location = 'path to file'; $handle = fopen($log_location, 'r'); flock($handle, LOCK_SH) || die('Could not obtain file lock.'); $contents = fread($handle, filesize($filename)); fclose($handle); ?> PHP: If that doesn't work, there are command line programs out there that can release file locks. You could execute it from the script, then open it for reading.