2

I have a D7 site that is hovering around 55mb on devel_shutdown(); for most uncached pages and has a lot of migrated content that has images linked to various styles around the site, many of which are currently ungenerated.

If I bump PHP memory usage allowance to 130mb (I'm on Dreamhost shared hosting, so 150mb is the top end for any individual process), images generate fine. If I leave it at the unmodified 90mb, image generation starts to fail.

It seems there are two options:

a. Get more RAM, through a virtual private server or some other hosting-related fix.

b. At my coworker's suggestion, find some fiddly way of getting images to generate ahead of a user running into them.

In terms of option B, we're using, gasp!, WordPress for an inspiration, which seems to handle images more intelligently in low-memory situations (Heresy! Madness! Spartaaaaaa!).

To explain — after the page has loaded and PHP has released memory, thumbnails are generated as they are uploaded, noticeable when WordPress says "Crunching" during the upload process. This way, there isn't any delay when a user then views them, and there's no worry that the combined memory load of the CMS and the image library will cause one of them to fail.

Is this at all possible in Drupal? Would a module like Cache Warmer do this if set up in a cron job? Is there even any benefit to doing things this way?

  • As mentioned below, I've since gone the "just get more RAM" route by upgrading to a VPS. I'm leaving this question open, however, in case someone has a solution to Option B. – aendrew Jul 6 '12 at 9:52
5

I don't like the "lazy" image style generation either. After I imported 100,000 photos I batch created image styles for all of them. I just looped over each image and created the 5 or 6 styles for each image.

I noticed that there isn't a big penalty for looping over images that already have all image styles generated. So you could just run a cron, say every hour, that loops over all images created or updated within the last hour (or two to be save) and create the image styles.

I used something like this to generate the image styles, just select which ones should get generated:

    foreach(image_styles() as $style) {
        if ($style['name'] = 'thumbnail' || $style['name'] = 'medium'){
            $dest = image_style_path($style['name'], $uri);
            print ' '.$style['name']. ', ';
            if (!file_exists($dest)) {
                image_style_create_derivative($style, $uri, $dest);
            }
        }
}

You'll just need to $uri variable, in my case I get it directly from the file_managed table since I ran a batch job.

  • Hi! Mind posting that code? This problem's come back again on one of the pages — apparently generating 20 thumbnails simultaneously is bad for memory? lulz. – aendrew Jul 10 '12 at 20:37
  • no problem, see above – uwe Jul 10 '12 at 21:21
2

http://drupal.org/project/imageinfo_cache This module generates imagecache presets on file upload. So yes it is possible and yes we use this in production and have seen some massive speed improvements from it. Currently D6 only. Totally configurable so certain file fields only generate these presets.

Also for D6 imagecache are some drush commands to generate various presets. http://drupal.org/node/587086

  • Interesting. We're looking for something like this for D7 on my job. Need help migrating? Consider this a shameless, off-topic co-maintainer application :P – amateur barista Jul 5 '12 at 21:22
  • File an issue in the issue queue. If you've developed other modules I'll give you access. If not I'll need to see some patches before I give you the keys. – mikeytown2 Jul 5 '12 at 21:32
  • I don't know why that last line brings the little GEICO reptile to mind. If I do get into the porting thing I'll open an issue and post at least an initial patch or more. – amateur barista Jul 6 '12 at 5:49
  • I should have mentioned I'm working on a D7 project. I've since gone the "just get more RAM" route, but amateur barista, please post an update here if you manage to get a D7 version going. Thanks! – aendrew Jul 6 '12 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.