Using WindowsXP, NTFS as the file system and php 5.3.2 had no problems with this test script
<?php define('SOURCEPATH', 'd:/test.xml'); if ( 0 ) { build(); } else { echo 'filesize: ', number_format(filesize(SOURCEPATH)), "\n"; timing('read'); } function timing($fn) { $start = new DateTime(); echo 'start: ', $start->format('Ymd H:i:s'), "\n"; $fn(); $end = new DateTime(); echo 'end: ', $start->format('Ymd H:i:s'), "\n"; echo 'diff: ', $end->diff($start)->format('%I:%S'), "\n"; } function read() { $cnt = 0; $r = new XMLReader; $r->open(SOURCEPATH); while( $r->read() ) { if ( XMLReader::ELEMENT === $r->nodeType ) { if ( 0===++$cnt%500000 ) { echo '.'; } } } echo "\n#elements: ", $cnt, "\n"; } function build() { $fp = fopen(SOURCEPATH, 'wb'); $s = '<catalogue>'; //for($i = 0; $i < 500000; $i++) { for($i = 0; $i < 60000000; $i++) { $s .= sprintf('<item>%010d</item>', $i); if ( 0===$i%100000 ) { fwrite($fp, $s); $s = ''; echo $i/100000, ' '; } } $s .= '</catalogue>'; fwrite($fp, $s); flush($fp); fclose($fp); }
exit:
filesize: 1,380,000,023 start: 2010-08-07 09:43:31 ........................................................................................................................ #elements: 60000001 end: 2010-08-07 09:43:31 diff: 07:31
(as you can see, I messed up the output of the end time, but I do not want to run this script for another 7+ minutes ;-))
Does this also work on your system?
As a side note: the corresponding C # test application took just 41 seconds instead of 7.5 minutes. In this case, my slow hard drive could be / the only limiting factor.
filesize: 1.380.000.023 start: 2010-08-07 09:55:24 ........................................................................................................................ #elements: 60000001 end: 2010-08-07 09:56:05 diff: 00:41
and source:
using System; using System.IO; using System.Xml; namespace ConsoleApplication1 { class SOTest { delegate void Foo(); const string sourcepath = @"d:\test.xml"; static void timing(Foo bar) { DateTime dtStart = DateTime.Now; System.Console.WriteLine("start: " + dtStart.ToString("yyyy-MM-dd HH:mm:ss")); bar(); DateTime dtEnd = DateTime.Now; System.Console.WriteLine("end: " + dtEnd.ToString("yyyy-MM-dd HH:mm:ss")); TimeSpan s = dtEnd.Subtract(dtStart); System.Console.WriteLine("diff: {0:00}:{1:00}", s.Minutes, s.Seconds); } static void readTest() { XmlTextReader reader = new XmlTextReader(sourcepath); int cnt = 0; while (reader.Read()) { if (XmlNodeType.Element == reader.NodeType) { if (0 == ++cnt % 500000) { System.Console.Write('.'); } } } System.Console.WriteLine("\n#elements: " + cnt + "\n"); } static void Main() { FileInfo f = new FileInfo(sourcepath); System.Console.WriteLine("filesize: {0:N0}", f.Length); timing(readTest); return; } } }