B
B
BushaevDenis2017-01-19 22:56:24
PHP
BushaevDenis, 2017-01-19 22:56:24

How to feed large xml(6MB) php?

How to feed php a pretty big xml file for parsing?
I have already written a script, debugged it on a lightweight xml file, and here is such a trick.
Since I am making a script for the user, I need maximum automation.
I feed the file using file_get_contents, then simple html dom parses it into a DOM tree.

$html = str_get_html(file_get_contents('content.xml'));

php7-x64 settings:
max_execution_time = 0
max_input_time = 0
;max_input_nesting_level = 64
; max_input_vars = 1000
memory_limit = 6G

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Nikolaev, 2017-01-19
@gromdron

Um ... Well, in general, 6MB is a rather small volume that fits into the RAM, so nothing more is needed. If this volume slows down, then maybe you don’t have parsing, but the operations themselves take a long time?
As for the topic - you can google xmlreade large files or "PHP SAX XML" they will tell you about the stream there ... But from memory it will come out about the same 6 mb

B
BushaevDenis, 2017-01-19
@BushaevDenis

Maybe I didn't express myself correctly. It doesn't hang - it loads for a long time, and then gives the result about the same - if I had an error in the parser, so I blame rather simple html dom

A
Anton Tikhomirov, 2017-01-20
@Acuna

Well, this is ... simple_html_dom is generally a very slow thing, because it parses everything with regular expressions, it's not for that at all. Look towards specialized XML solutions such as XMLReader . Open your file with this file_get_contents (), and go.

N
Nikolai Konyukhov, 2017-01-20
@heahoh

Try specialized libraries for working with xml, in theory they should be faster: SimpleXML , XMLReader .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question