In your case I think keeping the server from crashing tops MVC
design. :)

But considering how other things in CakePHP are organized you could
skip the view and output using a component or just a plain class.
Compare to something like EmailComponent, File class. Your email is
rendered by the email component not an email view. The view is for
returning the result of a request to the requesting browser. When
"rendering" to other outputs you exit through a side-door in Cakes MVC
layers. :)

One thing I have noticed is that out-of memory errors usually come
about the same time as php's max execution time (roughly). So if you
are going to be writing thousands of lines and worry about memory...
you also need to worry about time. Even if you increase the execution
time the browser will eventually give up waiting. What I am getting at
is wether this output will be triggered in a request or as a cron or
something similar?

Another related thing I have observed is that it probably won't be
your view causing problems. The View will only contain the resulting
text output (1MB of raw text is a lot). What will eat your memory
faster is the array-data used to generate the view. So you can
probably get away with just "paginating" (find with limit and page
set) your data in a loop and calling $this->render() each time and
saving the result (as suggested by djiize). It will still take a long
time. As a cron I have had my script go through 950'000 rows of quite
complex data and generating reports on it... a few thousand rows at a
time in a while-loop from a shell with no memory problems and the
normal website still running (not locking up).

Something like:
$page = 1;
while ( $all = $this->MyModel->find('all', array(
    'conditions'=>array(
        'MyModel.created >' => $startDate
    ),
    'recursive'=>'-1',
    'order'=>'MyModel.created ASC',
    'limit'=>'5000',
    'page' => $page++
))) {
    foreach ( $all as $one ) {
        // generate stuff here
    }
}


/Martin


On Oct 22, 5:08 pm, "Liebermann, Anja Carolin"
<[EMAIL PROTECTED]> wrote:
> Hi djiize,
>
> Thanks for the hint. But my problem with the size of my view would still 
> remain.
>
> I guess in the end the view will contain several thousands (litearally) of 
> lines in xml and would cause a crash of either php / server / or browser. So 
> what I would like to do is write chunks of data from the view output into a 
> file while it is generated and not after I have a big servercrashing datablob.
> Any idea?
>
> Background information: I program a product information system and in the end 
> all gathered data should go to an xml-export file for e.g. a WCMS, catalogue 
> or a distributor.
>
> Greetings Anja
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[EMAIL PROTECTED] Im Auftrag von djiize
> Gesendet: Mittwoch, 22. Oktober 2008 16:55
> An: CakePHP
> Betreff: Re: Write view output to file - best MVC approach?
>
> in Controller code, a call to $this->render() returns the content of the view 
> HTH
>
> On 22 oct, 15:49, "Liebermann, Anja Carolin"
>
> <[EMAIL PROTECTED]> wrote:
> > Hi everybody,
>
> > I make good progress with my xml-export.
> > Since I expect the output to become very big, I would like to write
> > the resulting view rather to the harddisk to download later than show
> > it on the screen.
>
> > Now my questions:
> > In my controller I have an function which could write strings in a file.
> > But my strings are composed in my view!
>
> > What is the best approach to stay in the MVC world?
>
> > Call the write function form the view? Or transfer all foreach logic
> > to the controller? If I do the second what do I do with strings I have
> > put in elements?
>
> > If I want to avoid an overflow in my RAM do I have to flush something
> > in between?
>
> > Thank you for your opinion and any hints!
>
> > Anja
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to