Jump to content

[SOLVED] PHP Read constantly updating CSV File?


Fragmaggot

Recommended Posts

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.