0

Suddenly, my code that has been working well started returning this error Message:

XMLReader::read(): compress.zlib://file.gz:2: parser error : internal error: Huge input lookup

This is happening on a cpanel server, but when I run it on my localhost, it runs properly.

I tried raising the memory limit on the server.

Any advice would be welcome.

6
  • Have you tried XML_PARSE_HUGE? stackoverflow.com/q/5428055/231316 Commented May 10, 2023 at 4:05
  • I am using the XMLReader library. My code looks like this: Commented May 11, 2023 at 9:34
  • ini_set("memory_limit","20000M"); $file = 'file.gz'; $reader = new XMLReader(); $xmlfile = "compress.zlib://{$file}"; $reader->open($xmlfile); //Read from the xml file. while ($reader->read()) { continue; } $reader->close(); exit("\nLoop Completed\n"); Commented May 11, 2023 at 9:53
  • The link shared by Chris uses simplexml_load_string() php function which can not handle large data files Commented May 11, 2023 at 9:56
  • The third parameter to open() is flags to which you can pass LIBXML_PARSEHUGE which sets XML_PARSE_HUGE Commented May 11, 2023 at 11:56

1 Answer 1

1

Following Chris Haas' advice, I modified my code to add LIB_XML_PARSEHUGE and it worked. My code now looks like this:

ini_set("memory_limit","20000M"); 
$file = 'file.gz'; 
$reader = new XMLReader(); 
$xmlfile = "compress.zlib://{$file}"; 
$reader->open($xmlfile,null,LIBXML_PARSEHUGE); 
while ($reader->read()) 
{ 
   //My logic here 
} 
$reader->close();
Sign up to request clarification or add additional context in comments.

1 Comment

Also, if you are on PHP 8.0 or greater, you can omit the second parameter and directly access the third parameter using a name: $reader->open($xmlfile, flags: LIBXML_PARSEHUGE).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.