Mailing created objects to users

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EricW
Forum Newbie
Posts: 3
Joined: Tue Nov 14, 2006 8:54 pm

Mailing created objects to users

Post by EricW »

Hi, I've written a short script which creates a rather large object (a PDF file) using FPDF, based on some form input.

At the moment the form page passes on a group of variables to the php file generating the PDF, and the user's browser waits while the server takes its time putting the file together. I would like for the user to be able to enter the desired input in the form (including an e-mail address), and be directed immediately to a page notifying them that when their PDF is complete, a link to it will be mailed to them.

How can I go about achieving this? Are there any open source tools that might help?

I am relatively new to PHP, so any advice on how to minimise server processor usage for such an operation would also be appreciated. Do you think it would be easier to email the file to the user (the files are 2 to 3 MB max)?

Thanks in advance.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You could send it as a file attachment if you really wanted to: http://www.swiftmailer.org/docs/tutorials/attachments
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Many times, when performing such an action one would output the HTML for the page prior to running the heavy processing. After which you can use the library d11 has lovingly provided.
EricW
Forum Newbie
Posts: 3
Joined: Tue Nov 14, 2006 8:54 pm

Post by EricW »

Thanks! I think sending the file itself will be the way to go, rather than setting up temporary directories and pages for each user which have to expire after a set time.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

EricW wrote:Thanks! I think sending the file itself will be the way to go, rather than setting up temporary directories and pages for each user which have to expire after a set time.
Just looking at the size of the file you're talking about here. The current release may go beyond the 8MB limit since base64 encoding will turn 3MB of data into 4MB and then Swift needs to copy data around etc.

The new version out in (I hesitate to say) about 3 days contains objects which specifically work to lower memory usage by encoding file data on-the-fly. My suggestion (since it's generated by lib pdf) is to dump the data to a tmp file and null it from memory then load that file into a message.

Dealing with large strings is fairly intensive for PHP. You need to really think hard about where you can save memory without a big expense of time/cycles.
EricW
Forum Newbie
Posts: 3
Joined: Tue Nov 14, 2006 8:54 pm

Post by EricW »

Thanks for the thoughtful advice d11.

Would this problem be solved if we went for the direct download route rather than e-mailing the file? I have no definite preference for either (although your library will make the job much simpler), and am trying to find which method would put less load on the server.

Is this something I'll just have to test on my server?
Post Reply