[SOLVED] disk caching for attachments

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
whiskeyseven
Forum Newbie
Posts: 7
Joined: Mon Apr 16, 2007 11:03 am

[SOLVED] disk caching for attachments

Post by whiskeyseven »

hello,

i've been having trouble exceeding php's memory limit when adding large attachments (20mb or more) so i've implemented the disk caching technique as described in the documentation regarding "keeping memory down to a minimum"

however, when i include the following two lines:

Swift_CacheFactory::setClassName("Swift_Disk_Cache");
Swift_Disk_Cache::setSavePath("path removed for privacy");

i get the following error:

Code: Select all

[Tue Apr 17 11:40:47 2007] [error] [client 74.132.209.182] PHP Warning:  Swift_ClassLoader::require_once(/swift/lib/Swift/../Swift/Disk/Cache.php) [<a href='function.Swift-ClassLoader-require-once'>function.Swift-ClassLoader-require-once</a>]: failed to open stream: No such file or directory in /swift/lib/Swift/ClassLoader.php on line 35, referer: http://67.59.3.94/messages/compose.php
[Tue Apr 17 11:40:47 2007] [error] [client 74.132.209.182] PHP Fatal error:  Swift_ClassLoader::require_once() [<a href='function.require'>function.require</a>]: Failed opening required '/swift/lib/Swift/../Swift/Disk/Cache.php' (include_path='.:/usr/share/pear:/usr/share/php') in /swift/lib/Swift/ClassLoader.php on line 35, referer: http://67.59.3.94/messages/compose.php
it seems to be searching for the file "Cache.php" in the directory "Disk"
however, in the file structure as it is currently distributed, the file "Disk.php" exists in the folder "Cache"

is this merely a typo, and hence a bug? what's the best solution for fixing this?

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

Post by Chris Corbyn »

Apologies, that must be a typo in the docs:

Code: Select all

Swift_CacheFactory::setClassName("Swift_Cache_Disk"); 
Swift_Disk_Cache::setSavePath("path removed for privacy");
EDIT | If you're saving memory, remember to use Swift_File when you add the 20MB attachment. 20MB is fine, 100MB is fine, heck even 1GB will be fine if you're using the disk cache and Swift_File since you're streaming data both ways :)

EDIT 2 | Documentation corrected.
whiskeyseven
Forum Newbie
Posts: 7
Joined: Mon Apr 16, 2007 11:03 am

Post by whiskeyseven »

i was thinking that the problem is in the code.

the 2 lines you quoted were simply from my script.

the errors are being generated by your classes looking for a file that doesn't exist. you've hard-coded your routine to search for "Cache.php" when in reality it should be looking for "Disk.php" in the FOLDER "Cache"

am I making sense?

anyway, rather than trace through all the code, i was hoping you could tell me where it needs to be changed, as well as take note if this is indeed something that should be fixed for the next release.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Read my code in my last post again:

Swift_Disk_Cache != Swift_Cache_Disk ;)

That is the fix.

EDIT | To clarify, Swift is trying to load a file using PEAR naming. It's just turning "_" into "/" then looking for the file.
whiskeyseven
Forum Newbie
Posts: 7
Joined: Mon Apr 16, 2007 11:03 am

Post by whiskeyseven »

oops! i see what you mean. the change was so slight that i missed it :)

i've changed my code and it seems to be working.

don't forget to change the second line in the documentation as well, however:

Code: Select all

Swift_CacheFactory::setClassName("Swift_Cache_Disk");
Swift_Cache_Disk::setSavePath("path removed for privacy");
I got an error initially when it couldn't find the class.

thanks for your help!
w7
Post Reply