Re: [scalability, performance, DoS] To or not to process images at runtime
| From: | Per Jessen | Date: | Thu, 07 Aug 2008 08:17:37 +0000 |
| Subject: | Re: [scalability, performance, DoS] To or not to process images at runtime | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-277799@lists.php.net to get a copy of this message | ||
Marcelo de Moraes Serpa wrote:
> Less manegeable becouse I would have to keep copies of the pictures on
> the disk. If I ever want to change these watermarks, I would have to
> somehow recreate them. It is more work to do than if I used the
> per-request runtime applying of watermark approach, since in this
> case, I would just apply the watermarks I wanted and then serve the
> stream directly from memory.
Hmm, I don't usually think "more work" = "less managable", but that's
a
matter for you.
My personal take on this type of thing -
I would go for the on-demand watermarking, but with a cached copy of
everything that is watermarked. "on-demand" = "when a photo is
published the first time". Like Bernhard said earlier, it probably
takes a few milliseconds to apply a watermark, so the very first time a
photo is viewed, the viewer might just experience the slightest delay.
With apache this is really easy to do:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.+)$ apply_watermark.php?name=$1
This means: if <photo-with-watermark> doesn't exist,
run "apply-watermark.php" to apply a watermark, write the
<photo-with-watermark> to cache/disk, and then output the watermarked
photo.
If you need to change the watermark, just erase the cached copies and
they're regenerated next time someone wants to view a photo. To save
on disk-space if that is a concern, you can run regular purges of
cached copies that haven't been viewed for a while:
find <cachedir> -atime +30 -type f | xargs rm
/Per Jessen, Zürich