0

I am using PHP library GeSHi to highlight XML files content. It works fine for small files. But when I want to highlight big file (200k lines) an error occurs: Allowed memory size of 536870912 bytes exhausted...

How I did it:

$xmlContent = $domXml->asXML(); // SimpleXML

$geshi = new GeSHi($xmlContent, 'xml');
$highlitedContent = $geshi->parse_code();

unset($geshi);

Is there are ways to highlight XML like GeSHi with low memory usage? Maybe there are ways to optimize GeSHi highlight process without memory limit increasing?

Thank you!

Meadow Lizard
  • 330
  • 2
  • 7
  • 19
  • It's probably best if you can post some code how you did it. That way we can see if there were problems with your loops, object reuse, etc. – aljo f Jun 19 '17 at 07:25
  • Unless you want to rewrite the library I honestly doubt there's a way to change its memory requirements. You may want to upgrade PHP (newer versions often include optimisations) but that's all. – Álvaro González Jun 19 '17 at 09:46

1 Answers1

0

No, GeSHi's memory requirements increase with the length of the string to be highlighted. This is a known problem without a solution.

cweiske
  • 30,033
  • 14
  • 133
  • 194