Question

I have a script that runs every 20 minutes that imports log data from a CSV into my database. Some log files may have 20 entries and some may have over 400,000. My challenge is this....the log files may change or grow within the intervals that my routine runs. On the next import, I'd like to pick up at the last log entry that was imported during the previous routine run instead of having to drop the data from my table and reimport the entire log file. Is this even possible?

At the moment, my code is:

if (($handle = fopen("/STORAGE/logfile.txt", "r")) !== FALSE)
    {
        while (($columnsUser = fgetcsv($handle, 1000, ",")) !== FALSE)
            {
                etc

So, for example, if at 12:20, the log file has 1000 entires, I import all of them. At 12:40, I'd like to start at line 1001 if there are more.

Thank you!

Was it helpful?

Solution

You can do this with ftell and fseek. http://php.net/manual/en/function.ftell.php http://php.net/manual/en/function.fseek.php Store the location in a database for later reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top