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.

Krokomot
  • 3,208
  • 2
  • 4
  • 20
  • Have you tried `XML_PARSE_HUGE`? https://stackoverflow.com/q/5428055/231316 – Chris Haas May 10 '23 at 04:05
  • I am using the XMLReader library. My code looks like this: – Basooma John May 11 '23 at 09: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"); – Basooma John May 11 '23 at 09:53
  • The link shared by Chris uses simplexml_load_string() php function which can not handle large data files – Basooma John May 11 '23 at 09:56
  • The third parameter to [`open()`](https://www.php.net/manual/en/xmlreader.open.php) is `flags` to which you can pass [`LIBXML_PARSEHUGE`](https://www.php.net/manual/en/libxml.constants.php#constant.libxml-parsehuge) which sets `XML_PARSE_HUGE` – Chris Haas May 11 '23 at 11:56
  • You are the best Chris. This has worked. – Basooma John May 11 '23 at 14:24

1 Answers1

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();
  • 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)`. – Chris Haas May 11 '23 at 14:37