Greetings i am trying to zip up many images into a folder that are being brought down from amazon s3 however it seems to always time out at between 20 and 44 pictures.
There should be 47 images in total, though in the future it may be even more. I am pretty sure i am running out of ram, the VPS has 256MB ram.
I have tried to refactor the code to be more and more efficient but i am now running out of ideas.
The file seems to return a server error by just trying to download the images too. So it may be a problem with that side of things.
$amazon_params = AmazonS3::first();
$amazonS3 = new s3;
$amazonS3::setAuth($amazon_params->accesskey, $amazon_params->secretkey);
$gallery = Gallery::find(array('conditions' => array("slug = ?", $this->_request->getParam('slug'))));
$photos = Image::all(array('conditions' => array("gallery_id = ? ORDER BY title Limit 0,10", $gallery->id)));
if ( $amazonS3::getObjectInfo($amazon_params->bucket, $amazon_params->image_s3.'/zip/'.$gallery->slug.'.zip', true) === false)
{
$path = dirname(dirname(dirname(dirname(dirname(__FILE__))))). "/tmp/zip/";
if (!$path . $gallery->slug) {
mkdir($path . $gallery->slug, 0777);
}
$i = 0;
// New Zip Archive
$zip = new ZipArchive();
$zip->open($path.$gallery->slug.'.zip', $overwrite = false ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE);
foreach ($photos as $photo) {
$i++;
$file = $path . "/" . $gallery->slug . "/" . $i . ".jpg";
$amazonS3::getObject($amazon_params->bucket, $amazon_params->image_s3 . $photo->file, $file);
$zip->addFile($file,basename($file));
}
$zip->close();