Created
July 14, 2015 18:32
Star
You must be signed in to star a gist
Bug Test-Script: Memleak when calling PHP functions from XSL with nodes as parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// create big dummy document: | |
$dom = new \DOMDocument(); | |
$rootNode = $dom->appendChild($dom->createElement('root')); | |
for ($i = 0; $i <= 100; $i++) { | |
$level1Node = $rootNode->appendChild($dom->createElement('level1')); | |
for ($j = 0; $j <= 100; $j++) { | |
$level2Node = $level1Node->appendChild($dom->createElement('level2')); | |
for ($k = 0; $k <= 10; $k++) { | |
$level3Node = $level2Node->appendChild($dom->createElement('level3', 'test')); | |
} | |
} | |
} | |
function testPhpFunction($node) { | |
return 'test2'; | |
} | |
$xslStr = <<<EOF | |
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl"> | |
<xsl:template match="root"> | |
<output> | |
<xsl:for-each select="level1"> | |
<node> | |
<xsl:value-of select="php:function('testPhpFunction', .)" /> | |
</node> | |
</xsl:for-each> | |
</output> | |
</xsl:template> | |
</xsl:stylesheet> | |
EOF; | |
$xsl = new \DOMDocument(); | |
$xsl->loadXML($xslStr); | |
$xslt = new \XSLTProcessor(); | |
$xslt->registerPHPFunctions('testPhpFunction'); | |
$xslt->importStyleSheet($xsl); | |
$result = $xslt->transformToXML($dom); | |
echo 'Check process memory usage now (Press ENTER to exit): '; | |
fgetc(STDIN); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment