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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:40:36+00:00 2026-06-03T22:40:36+00:00

I have some pretty big xml files which used for scheduled import. I use

  • 0

I have some pretty big xml files which used for scheduled import. I use cron to parse them.
The problem is that processing takes too much time and always exceeds the php “max_execution_time”. Since I use XMLReader, that allows to read xml “line by line”, the only one solution I see: track current working “node”, memorize it and set node offset on next cron run.

Now I have

  $xml = new XMLReader;
  $xml->open($file);
  $pointer = 0;

  while($xml->read()) {

    if ($xml->nodeType == XMLReader::ELEMENT && $xml->localName == 'Product') {
      $chunk = array();
      $chunk['ProductID'] = $xml->getAttribute('ProductID');
      $chunk['ProductName'] = $xml->getAttribute('ProductName');
      process_import($chunk); // Process received date
      save_current_node_in_BD($pointer++); // insert current position in BD
    }
  }
  $xml->close();
}

Is it good idea to use $pointer++ to count processed nodes?
How to set an offset for next cron run?

  • 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-03T22:40:38+00:00Added an answer on June 3, 2026 at 10:40 pm

    First of all, when you execute php from the cron, you normally use the cli version which has a default max_execution_time of 0 (disabled). If you can’t change that, continue reading.

    If your XML can be parsed within time (parsing only, no processing) you can have two crons:

    1. The first cron will parse the XML and dump new tasks onto a pile.
    2. The second cron will take work from the pile, process it and then remove it from the pile.

    The pile can be implemented in a few ways, amongst which:

    • A database table
    • A directory of work items (each work item is one file)

    Edit

    If you can’t disable the execution time limit you can keep a small file comprising the file name and position. At each iteration you can open this file to determine if there’s still work to be done. To make sure it saves that file when the time ran out, you need to register a shutdown function.

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

Sidebar

Related Questions

We have pretty big (~200mb) xml files from different sources that we want to
I have been working on a site that makes some pretty big use of
I'm here to get some information. We have a product thats pretty big and
I have some files that are uuencoded, and I need to decode them, using
We have a pretty big perl codebase. Some processes that run for multiple hours
During my apprenticeship, I have used NHibernate for some smaller projects which I mostly
I have some pretty complex reports to write. Some of them... I'm not sure
I have some DataGrids with pretty standard one-line itemrenderers, but need to use a
These are probably are pretty simple YES|NO type questions. I have some NSDictionaries containing
I have been doing some research on test driven development and find it pretty

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.