Speeding up Process (Zip Photos, send 3 emails)

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);

			// Build E-mail to Purchaser
			$email = new \\Objects\\Email($this->name, $this->email, $this->subject, $this->message, \\Objects\\Configuration::CC_EMAIL_FROM);

			// 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);

			// Delete Zip

Use exec to create background PHP processes crunching on your script of choice.[URL=“http://www.php.net/manual/en/function.exec.php#107456”]


Yeah, I thought of that too, but part of the problem is I need to know the result. It seems after moving it to the remote server, the remote server is processing a LOT faster than my local setup (not sure why, has to be some PHP setting, as I’m running a Quad Core 2.7 Ghz 8 GB RAM server).

I’d have to use & to make sure it runs in the background so exec can return immediately, but that poses a slight problem in that it will be harder for me to know the end result (whether the emails were successful or if they failed). I could potentially build a notification system I guess.

I’ll keep that in mind too, just didn’t know if there were newer techniques being used (still wish PHP would adopt an async pattern, it would be AWESOME!).