[TYPO3-dev] EM, TER2, XML and other animals
Chi Hoang
chibox at gmail.com
Sat Apr 29 03:36:39 CEST 2006
Simon Child schrieb:
> Can anyone think of another/better way to load this extension data?
Problem was that the file was loaded into the memory in one piece and
then went encode and decode. This is bad style. What is if the extension
list is 20 MB big? Solution is to encode and decode the file on-the-fly.
It works great with my hoster (only 25 MB memory). Before I have had the
same problems like you.
Example:
Create compressed file:
t3lib_div::writeFile(PATH_site.'typo3temp/extensions.xml.gz', $extXML);
$start = '<?xml version="1.0"
encoding="utf-8"?><extensions>';
$end = '</extensions>';
$c = '';
$gz =
gzopen(PATH_site.'typo3temp/extensions.xml.gz', 'r');
$fd = fopen(PATH_site.'typo3temp/extensions.bin','wb');
while (!gzeof($gz)) {
$c .= gzgets($gz, 4096);
$pos = strpos($c,"</extension>");
if ($pos) {
$c = str_replace("<?xml version=\"1.0\"
encoding=\"utf-8\"?>",'',$c);
$c = str_replace("<extensions>",'',$c);
$result =
$this->xmlhandler->parseExtensionsXML($start.$c.$end);
$compressed =
gzcompress(serialize($this->xmlhandler->extXMLResult));
$res =
fwrite($fd,$compressed,strlen($compressed));
$res = fwrite($fd,chr(0xff),1);
$res = fwrite($fd,chr(0xff),1);
$res = fwrite($fd,chr(0xff),1);
$res = fwrite($fd,chr(0xff),1);
$res = fwrite($fd,chr(0xff),1);
$c = '';
$this->xmlhandler->extXMLResult = array();
}
}
gzclose($gz);
fclose($fd);
Load compressed file:
$handle = fopen (PATH_site.'typo3temp/extensions.bin', 'r');
while (!feof($handle)) {
$char = fgetc($handle);
$char .= fgetc($handle);
$char .= fgetc($handle);
$char .= fgetc($handle);
$char .= fgetc($handle);
if ($char ==
chr(0xff).chr(0xff).chr(0xff).chr(0xff).chr(0xff)) {
$array = unserialize(gzuncompress($buffer));
$this->extensionsXML =
array_merge($this->extensionsXML,$array);
unset($buffer);
} else {
$buffer .= $char;
}
}
fclose ($handle);
return true;
More information about the TYPO3-dev
mailing list