NYCPHP Meetup

[nycphp-talk] PHP Scope in foreach construct.

Daniel Convissor danielc at analysisandsolutions.com
Wed Jan 28 13:24:37 EST 2009


Hi Anthony:

On Mon, Jan 26, 2009 at 09:27:43AM -0800, Anthony Wlodarski wrote:

> When working with foreach constructs do the functions and variables 
> defined get returned to the garbage collector on each iteration or does 
> the foreach have to finish execution before things can be returned to 
> the garbage collector?

The test I provided in another email in this thread makes it seem like 
garbage collection is happening on each iteration.


> The reason that I ask is because we are generating data for Google Maps 
> and they require one very large XML file which keeps blowing our memory 
> size definition inside the php.ini file.

Are you storing the XML output in memory while you're looping then 
writing it to file?  Or are you writing it directly to the file while 
you're looping?  I'd do the latter when memory optimization is an issue.


> What we might end up doing is creating the XML file in batches of lets 
> say 500 items or less and then append the files manually.

That shouldn't be necessary.  Even if you go with that approach, you can 
append all output to one file rather than creating multiple files and 
merging those.

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list