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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.