Hi Michael, > Ok. It is probably about time I posted the awlfully slow section of > code for > people to look at and state their opinions-
First off I would replace your calls to filesize(), fopen(), fread(), and fclose() with a single call to file_get_contents(). From the manual: file_get_contents() is the preferred way to read the contents of a file into a string. It will use memory mapping techniques if supported by your OS to enhance performance. That's unlikely to lead to a huge performance increase given your regex call later, but it will help. The next thing I'd do is record and report on your microtime() delta for each loop iteration - that will show you the iteration(s) where things start slowing down. Within the loop I'd focus on the elapsed time for the call to preg_match_all() - regular expression matching is notorious for being slow, and you might have a particularly slow pattern/data combination going on. The other potential slowdown will be in reading the data from disk. Determine how long each file read takes (again using microtime()) and if there are spikes there you could try moving the data to another disk, or into memory if you have the RAM. While you're at it you should also collect and report memory usage (delta for each iteration and total) using memory_get_usage(). What's your total memory usage when things start slowing down? Let us know how you get on. Kind regards, James McGlinn __________________________________ CTO Eventfinder Limited Suite 106, Heards Building 2 Ruskin Street, Parnell, Auckland 1052 Phone: +649 365 2342 Mobile: +6421 633 234 [email protected] | www.eventfinder.co.nz --~--~---------~--~----~------------~-------~--~----~ NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected] -~----------~----~----~----~------~----~------~--~---
