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 6142591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:24:33+00:00 2026-05-23T18:24:33+00:00

My task is to parse a large .txt file (circa. 15,000 lines) into a

  • 0

My task is to parse a large .txt file (circa. 15,000 lines) into a MySQL database. The problem is I’m working with a 30 second maximum execution time. I’ve tried using this:

        $handle = @fopen('http://www.someothersiteyouknow.com/bigfile.txt', "r"); 
    if ($handle) { 
       while (!feof($handle)) { 
           $lines[] = fgets($handle, 4096); 
       } 
       fclose($handle); 
    }

I can then access the $lines array and parse the data whichever way I need to but it takes too long for the script to finish running. My feeling is that I should read the file in chunks, maybe 1000 lines at a time. But I only understand how to read from the beginning of the .txt file. Please may you impart some ideas for methods of doing this correctly? Just to clarify, I don’t require specific code examples, just ideas for how to parse large .txt files using PHP.

  • 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-05-23T18:24:34+00:00Added an answer on May 23, 2026 at 6:24 pm

    This doesn’t seem like the best idea, to be honest. What if multiple users access the same page at, or around, the same time? You’ll have (number of users*large text file) being processed concurrently.

    Suggest you bring the file local (save it locally if the file doesn’t already exist), and work with the local file. This should help reduce your transaction time

    This should help bring you into the 30s limit … if the file doesn’t take longer than 30s to download!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem with CompletionService. My task: to parse parallely for about 300
I have following task to do: to fill spell check dictionary (simple txt file)
I would like to parse text and separate it into tasks and subtasks: 'Asubsubsubtask:Bsubtask:Ctask:D'.split(/((sub)*task)\:/i)
I'm using SQL Server 2008. The task: take an XML file and parse it
Task: implement paging of database records suitable for different RDBMS. Method should work for
Here's my batch file to parse a directory, and zip files of certain type
I have a text file that lists the names of a large number of
I am (too) often confronted with the task of having to parse textual data
I am working on task involving reading from the socket trading quotes and I
I'm trying to use SQL Server Integration Services (SSIS) to parse an XML file

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.