0

I have a csv file named data1.csv. The first time i use php to read the csv file content I can get the contents correctly. The problem is I cannot read the new data after I update the data in data1.csv. It keeps returning the previous data. What could be the wrong?

    $file_handle = fopen($csvFile, 'r');
    if(!$file_handle) die("Can't open file");

    while (!feof($file_handle) ) {
      $line_of_text[] = fgetcsv($file_handle, 0, $csv_spliter);

    }

    clearstatcache();

    fclose($file_handle);
    $file_content = $line_of_text;
12
  • Is the code from the read that works? Could you show the one that is not working and how you update the csv file? Commented Nov 5, 2018 at 12:57
  • This code can read the csv content. The csv is updated manually Commented Nov 5, 2018 at 13:00
  • Do you also get the old data if you completely delete the file? If it only affects new lines it could be a line ending problem. Commented Nov 5, 2018 at 13:03
  • 1
    did you check is data saved properly or not? Commented Nov 5, 2018 at 13:13
  • 2
    @ovicko That's your problem right there. See this question: stackoverflow.com/questions/511476/… Commented Nov 5, 2018 at 13:34

1 Answer 1

1

Since you are retrieving data via http/https, it is most likely being cached. See Does PHPs fopen function implement some kind of cache?

Sign up to request clarification or add additional context in comments.

3 Comments

I have tried using solutions stated still no difference
Did you try adding a unique query string to the URL every time you attempted to fetch it, e.g. https://example.com/feed/data1.csv?12345?
@ovicko If my answer works for you, please consider marking it as the accepted answer, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.