Page 1 of 1

[SOLVED] disk caching for attachments

Posted: Tue Apr 17, 2007 10:52 am
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

Posted: Tue Apr 17, 2007 12:09 pm
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.

Posted: Tue Apr 17, 2007 12:15 pm
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.

Posted: Tue Apr 17, 2007 12:17 pm
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.

Posted: Tue Apr 17, 2007 12:34 pm
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