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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:08:14+00:00 2026-06-09T05:08:14+00:00

I have a PHP script to import various data from text files. The import

  • 0

I have a PHP script to import various data from text files.

The import is very complex and my test file has 32.000 entrys. These entrys have to be parsed and inserted into a mysql database.

If i will run my script it needs 30 minutes to finish… And at this time my server cpu is 99% idle.

Is there a chance to optimize php and mysql that they are using more power from the machine?

code:

if ($handle = @fopen($filename, "r")) {

    $canceled = false;
    $item = null;
    $result = null;

    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        $line = $buffer;

        if (substr($line, 0, 2) == '00') {

            continue;
        }
        else if (substr($line, 0, 2) == '99') {
            continue;
        }
        else if (strlen($line) < 75) {
            continue;
        }

        Reread:
        if ($canceled) {
            break;
        }

        if ($item == null) {
            $item = new DA11_Item();
            $item->boq_id = $boq_id;
        }
        $result = $this->add_line_into_item($item, $line);

        if ($result == self::RESULT_CLOSED) {
            $this->add_item($item);
            $item = null;
        }
        else if ($result == self::RESULT_REREAD) {
            $this->add_item($item);
            $item = null;
            goto Reread;
        }
        else if ($result == self::RESULT_IGNORD) {
            if (count($item->details()) > 0) {
                    $this->add_item($item);
            }
            $item = null;
        }
    }

    if ($item !== NULL) {
        $this->add_item($item);
    }

    fclose($handle);
}

add_item will perform a $item->save() and saves it to the database.

thx and kind regards,
viperneo

  • 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-09T05:08:16+00:00Added an answer on June 9, 2026 at 5:08 am

    One problem you have is that every single insert is a separate request to your db-server including it’s response. With 32.000 records you maybe get an idea, that this is a quite huge overhead. Use bulk inserts for (lets say) 1000 records at once

    INSERT INTO foo (col1, col2) VALUES
      (1,'2'),
      (3,'4')
      -- 997 additional rows
      (1999, '2000');
    

    Additional Transactions may help

    Update, because you mentioned active-record: I recommend to avoid any additional abstraction layer for such mass import tasks.

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

Sidebar

Related Questions

I have the below script to import data from a csv file on my
I have a php script that inserts data from an Android app into a
i have to parse files logs (5gb) error logs (1gb) import data file (csv)
i have two files. In first (parent, address: www.myaddress.com/fun/test.php) is jQuery function: <script type=text/javascript>
I have a PHP script running on my LAMP server that requires certain files
I have a php script that watches for the newest json file in a
I have a php script that grabs links from another website. I am storing
I have a PHP script that very much like a commenting system, but requires
I have created a php script to import rss feed into the database. The
I have a PHP script that imports and parses XML files and saves the

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.