Okay, so I’ve been working with a way to send photos to a third party so they can be purchased from an online gallery. In the end, the quickest and dirtiest to implement was an E-mail feature that Snapfish offers (you email the photos or a zip containing the photos to Snapfish).
The process works, but it is definitely slow on my local server (haven’t tested it on a remote server yet). It is understandable why it is a bit slow, compressing a couple megs of photos and then sending them as an email attachment results in a bit of processing.
Ideally what I would LOVE to do is to process all three email simultaneously. Unfortunately, much to my dismay, PHP still hasn’t implemented an async pattern.
I could run the command via a shell script so it zips, and sends the emails and I’d be able to run all three email sends together, but I’m not sure I want to take that approach. Does anyone have any better ideas?
Here is the code to give you an idea of what is happening and in what process (One thing to note: One of the three emails does not contain the attachment, so I guess I could combine the two that DO have the attachment, but they have separate bodies… so it really is three separate emails).
// Send Request
public function SendRequest($form)
{
// Create Zip
$zipArchive = new \\Objects\\Zip();
$photosForZip = $this->GetPhotos();
foreach ($photosForZip as $photo)
{
if ($this->ValidatePhoto($photo->Name, $photo->Image))
{
$zipArchive->AddFile($photo->Name, $photo->Image);
}
}
$zipArchivePath = $zipArchive->Create();
// Build E-mail to Snapfish
$email = new \\Objects\\Email(null, \\Objects\\OrderPrints\\Snapfish::EMAIL_TO, $this->subject, 'Snapfish Upload', \\Objects\\Configuration::SNAPFISH_EMAIL_ACCOUNT, $zipArchivePath);
$email->Send($form);
// Build E-mail to Purchaser
$email = new \\Objects\\Email($this->name, $this->email, $this->subject, $this->message, \\Objects\\Configuration::CC_EMAIL_FROM);
$email->Send($form);
// Build E-mail to CC TO
if (strlen(\\Objects\\Configuration::CC_EMAIL_TO) !== 0)
{
$email = new \\Objects\\Email(\\Objects\\Configuration::CC_EMAIL_NAME, \\Objects\\Configuration::CC_EMAIL_TO, $this->subject, $this->message, \\Objects\\Configuration::CC_EMAIL_FROM, $zipArchivePath);
$email->Send($form);
}
// Delete Zip
unlink($zipArchivePath);
}