Jump to content

CSV export database dump - memory error


_tina_

Recommended Posts

Hi,

 

I'm trying to export to a csv/xls file.  The user clicks a link, which calls a function that queries the database and prompts them with a download dialog.

 

I have an array of results, everything works fine, BUT, when I have 8000+ results, I get a PHP memory error.  Is there any way around this?

 

Thanks in advance!

 

Link to comment
Share on other sites

Any time you have an application that processes an ever increasing amount of data, you need to use memory management techniques (i.e. process the data in discrete chunks instead of all at once.)

 

It's also possible that your existing code is using 2 or 3 times more memory than necessary, but is would take seeing your existing code to be able to help with what it is doing or where memory management could be added to it.

Link to comment
Share on other sites

Thanks for the reply.

 

Here is what I am doing:

            $this->setLayout(false);

    $q = Doctrine_Query::create()
	  ->select('*')
	  ->from('ContestSubmission s')
	  ->leftJoin('Contest c ON s.id = c.contest_id')
	  ->where('s.contest_id = ?', $request->getParameter('id'));
	$this->contest = $q->execute(array(), Doctrine::HYDRATE_ARRAY);	 


    	$this->getResponse()->setContentType('application/msexcel');

 

This is done using a PHP framework btw.

 

Regarding memory management, what would you suggest I do to rectify this?

Link to comment
Share on other sites

Without information from you as to what framework you are using, no one can directly help.

 

Unless the framework provides a method to process the data in blocks, you will either need to write your own code to extend the framework or you will need to write your own code and not use a framework.

Link to comment
Share on other sites

  • 2 weeks later...

Still haven't been able to resolve this.  I need, if a user clicks a link, a bd will be quieried and return send the rows to a csv file, which will then present the user with a doownload prompt.  The problem being that when there are 10,000+ records, I get a php memory error.  Is there a way around this at all?

 

Thanks for the replies so far and thanks for reading :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.