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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:50:55+00:00 2026-05-13T08:50:55+00:00

I open a 10MB+ XML file several times in my script in different functions:

  • 0

I open a 10MB+ XML file several times in my script in different functions:

$dom = DOMDocument::load( $file ) or die('couldnt open');

1) Is the above the old style of loading a document?

I am using PHP 5. Oppening it
statically?

2) Do I need to close the loading of the XML file, if possible?

I suspect its causing memory problems because I loop through the nodes of the XML file several thousand times and sometimes my script just ends abruptly.

Thanks all for any help

  • 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-13T08:50:55+00:00Added an answer on May 13, 2026 at 8:50 am

    Using a DOM parser, the whole XML document is loading in memory — which can lead to problems when working with a big document (I know, you probably don’t have much of a choice)

    First of all, I would try not to open the same document more than once :

    • it means more work for PHP : it has to parse a big document several times, and, each time, build the DOM tree in memory
    • it might require more memory — In theory, when leaving the function in which you instanciated the DOMDocument object, its destructor should be called, and memory released, but, who knows…

    About the “Is the above the old style of loading a document“, well, looking at the documentation for DOMDocument::load, it seems it can be called both dynamically (see the example) and statically (see the return value section) ; so, I suppose both solutions are OK, and there is no “old way” nor “new way”.

    What do you mean by “my script just ends abruptly” ? Do you have a Fatal Error about memory_limit ?

    If yes, if you can change that kind of configuration setting, it might help to set memory_limit to a higher value.

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

Sidebar

Related Questions

open $FP, '>', $outfile or die $outfile. Cannot open file for writing\n; I have
The Open button on the open file dialog used in certain windows applications includes
I want to open a file for reading, the C++ way. I need to
This is my first Perl script. Ever: #!/usr/bin/perl if ($#ARGV < 1) { die(usage:
I am working on a Perl script to read CSV file and do some
I open a file in C# with FileStream, and I got the file handle
Open source implementation will be preferred.
Open up a Rails console and enter this: 2.weeks.ago.between? 2.weeks.ago, 1.week.ago Did it give
The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for
I open a connection like this: Using conn as New OdbcConnection(connectionString) conn.Open() //do stuff

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.