phpmemory-managementgeshi

PHP GeSHi highlight large string


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!


Solution

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