question on performance with php5/xml/xslt streams IO

[email protected] (Bill Hoffman) Fri, 7 May 2004 09:32:25 -0700
Newsgroups php.xml.dev
Message-ID <[email protected]>
I have an xsl stylesheet that merges the content of multiple remotely 
located xml files into a single xml file. An xml doc passed to a 
stylesheet contains the URI for each source file, as in:

<files>
	<file>http://www.somewhere.com/file1.xml</file>
	...
	<file>http://www.somewhere.com/file12.xml</file>
</files>

The xsl stylesheet grabs each remote file URI from the xml passed to it 
in a for-each loop, then does it stuff with each, as in:

<xsl:for-each select="//file">
	<xsl:variable name="file" select="document(text())" />
	... do stuff here
</xsl:for-each>

Each remote xml source file that gets fetched with the 
"select=document()..." expression is in fact quite small (a single, 
one-line element) but processing takes FOREVER when doing it with PHP5, 
as in:

$xsl = new domDocument();
$xsl->load('mystylesheet.xsl');
$xml = new domDocument();
$xml->load('mysource.xml');
$xslt = new XsltProcessor();
$xslt->importStylesheet($xsl);
print $xslt->transformToXml($xmlDom);

If I do this transform with xsltproc on the command line, the whole 
thing is done in just over 2 seconds (an eyeballed figure, yes, 
but...). If I do this transfom in PHP5 as above, it takes over 20 
seconds to complete. The latency with streams and remote URI sources is 
so pronounced that I'm using:

$transformResult = shell_exec('xsltproc mystylesheet.xsl mysource.xml');

...instead of the PHP5 dom/xslt functions to get acceptable performance 
in a production script. I'm puzzled as to how I should understand this, 
and what I could be doing differently. It seems to me that it's a 
performance issue related to PHP5 and streams, and not to dom or xslt 
functions. Or is there something going on in the PHP5 dom/xml/xslt side 
that is not going on in xsltproc that I need to understand and can do 
something about?

Sorry for long-windedness, trying to be throrough in describing things. 
Thanks in advance for any response.

--
Bill Hoffman
[email protected]


from phpinfo():

PHP Version => 5.0.0RC2
Registered PHP Streams => php, file, ftp, gopher, telnet, dict, ldap, 
http, https, ftps, compress.zlib
CURL support => enabled ( * config --with-curlwrappers)
CURL Information => libcurl/7.11.0 OpenSSL/0.9.7b ipv6 zlib/1.1.4
DOM/XML => enabled
DOM/XML API Version => 20031129
libxml Version => 2.6.8
HTML Support => enabled
XPath Support => enabled
XPointer Support => enabled
Schema Support => enabled
RelaxNG Support => enabled
libXML support => active
libXML Version => 2.6.8
libXML streams => enabled
XML Support => active
XML Namespace Support => active
libxml2 Version => 2.6.8
XSL => enabled
libxslt Version => 1.1.6
libxslt compiled against libxml Version => 2.6.8
EXSLT => enabled
libexslt Version => 1.1.6