0

Like xml_parse() (see xml_parse No memory error PHP ) the function xml_parse_into_struct() seems to have memory troubles.

Parsing an XML file (size over 9MB) gives me the error 'No memory' on the last line, last char.

$report_errors = true;

$parser = xml_parser_create('UTF-8');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);

xml_parse_into_struct($parser, $data, $vals);

if ($report_errors) {
    $errorcode = xml_get_error_code($parser);
    echo xml_error_string($errorcode) . ' line ' .
        xml_get_current_line_number($parser) . ' column ' .
        xml_get_current_column_number($parser) . PHP_EOL;
    // No memory line 3876 column 8
}
xml_parser_free($parser);

When I do not ask for errors, everything is fine: (But I do not trust it)

$report_errors = false;

Is there a way to implement chunk loading (as in link mentioned above) with xml_parse_into_struct()?

( Debian 9.5 amd64, PHP 7.0.30, libxml2 2.9.4 )

euneuber
  • 1
  • 1
  • 1
  • Not sure if it will cope with the files your reading, but have you tried using the SimpleXML library instead? https://stackoverflow.com/questions/8775669/how-to-parse-xml-file-using-php may help. – Nigel Ren Aug 28 '18 at 14:58
  • I believe you can find your answer here https://stackoverflow.com/questions/19152613/xml-parse-no-memory-error-php – unixmiah Aug 28 '18 at 15:17
  • @unixmiah this is the same link as I wrote in my first line. As I understood `xml_parse_into_struct()` this function needs to see the whole XML string, not only a chunk at a time. – euneuber Aug 30 '18 at 06:06
  • @nigelRen do you know of any replacement of `xml_parse_into_struct()` with SimpleXML? (this is only a small part of a bigger project and I cannot rewrite all of their code) – euneuber Aug 30 '18 at 06:36

0 Answers0