Fragmaggot Posted August 3, 2009 Share Posted August 3, 2009 Hey PHPF, I have a quick question to ask you php experts. Im trying to determine the feasibility of using php to read a CSV file while it is being appended to live. The situation is: Theres 4 Machines, with black boxes attached sending information via bluetooth to a linux box, appending to a CSV File. Theres 3 shifts per day, and there will be a text file(CSV) for each shift. I need to write a script, that will read and update the summarised information on a screen, updated for each entry. I think the box will be getting a few entries every 30 seconds and updating the text file. Is it possible to read the file while its updating? Thanks Alot Freaks Frag. Quote Link to comment Share on other sites More sharing options...
btherl Posted August 3, 2009 Share Posted August 3, 2009 It's certainly possible. One way would be to use the unix "tail -f" command with popen(). Or if you want to roll your own, you could remember the offset of the end of the csv file last time you read it, and start reading from there the next time you open it. fopen(), fseek(), read until end of file, ftell(), fclose(). As long as your writers are using the append only mode for writing to the file, lines will be written atomically and you don't need to worry about getting partial lines. Quote Link to comment Share on other sites More sharing options...
Fragmaggot Posted August 3, 2009 Author Share Posted August 3, 2009 TYVM Mate - This is exactly what i was looking for Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.