Для получения полного доступа

All snippets tagged with "buffer" tag

  • Reputation: 349
  • Snippets: 57
  • Revisions: 5

The approach demonstrated is used in my Sitemap package to allow generating huge sitemaps consisting of hundreds thousangs of locations.

// we'll buffer data in memory in order not to write too often
$bufferSize = 1000;

$filePath = 'test.xml';

$writer = new XMLWriter();
// using memory for buffering

$writer->startDocument('1.0', 'UTF-8');

while ($i < 10000) {                  
	if ($i % $bufferSize) {
		// if buffer is full, flush its contents into the file
		file_put_contents($filePath, $writer->flush(true), FILE_APPEND);
	$writer->writeElement('item', $i);



// write the rest of the buffer
file_put_contents($filePath, $writer->flush(true), FILE_APPEND);