Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:49:31+00:00 2026-06-09T16:49:31+00:00

I’m working on a CSV upload that has 35,000 lines of stuff going on

  • 0

I’m working on a CSV upload that has 35,000 lines of stuff going on and I’m trying to think of a way to start my parsing of the CSV file at line “X”. I’ve been refreshing the page and saving the line I was last on each time so it would fix the timeout issue I was having with browsers. Now, I just need to know how to start my CSV file on that line I left off.

while(($data = fgetcsv($handle, 0, ",")) !== false) {
    if($i > 2000) { break; }
    //start parsing here
    $i++
}
$_SESSION['lastLine'] = $i;
$_SESSION['filepath'] = $filepath;
//resend headers

I save the filepath as a session as well because it’s been uploaded to a temporary folder and I can re-access it. So the first time I upload, I go through all 2000 lines perfectly happy. The headers reset and start the process again, but since $_SESSION[‘lastline’] is now 2001, the code breaks (which is fine). What I need to figure out is how can I start my parsing on line 2001 and break again on 4000. This will continue until all 35,000 lines are done.

I was thinking about setting the break statement before the parsing to say:

if($i < $_SESSION['lastLine']) { $i++; }
if($i > $_SESSION['lastLine'] + 2000) { break; }

My problem is, doing 35,000 lines of CSV means that the last 10 or so runs will have to do an i++ loop thousands of times before the parsing even begins. I looked around for some ways to just start the CSV file at line “X”, which would be my preferred method of doing this, but I couldn’t find anything. Any help would be awesome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:49:32+00:00Added an answer on June 9, 2026 at 4:49 pm

    Use ftell() to save your position within the file. You can then fseek() to that position before restarting your fgetcsv() loop, e.g.

    while($row = fgetcsv($handle)) {
        $cur_pos = ftell($handle);
        if ($some_condition) {
              break;
        }
    }
    .....
    
    fseek($handle, $cur_pos); // jump back to last position
    ... continue on wards ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.