Dozens of media/images being created and then deleted on every page request

Hi,

I’m administrating a server with several Kirby sites. I recently noticed that during every page load, dozens of images are being created within the media/ folder structure, and then deleted immediately after. Are these sites misconfigured? Shouldn’t these images stay on the filesystem for subsequent requests? I believe they are scaled images. The srcset plugin is installed on both sites. Where should I investigate further?

Thanks for any advice

Yes, once created, the thumbs should stay where they are.

Kirby first creates job files, then these jobs are transformed into thumbs when the url is requested. Unless there are changes to the original, new thumbs are only created if the media folder or the thumbs in it are deleted.

What is the current version of these projects?

yeah, strangely, the scaled images are created and deleted in the same request. they never remain. i’ve done a find through the media/ directories, and there just aren’t any there. furthermore, i’ve monitored filesystem activity with inotifywait, and i see the sites create the images and then immediately delete them without a millisecond to spare. one installation is kirby 3.4.4, another is 3.4.2. both running through nginx and php 7.2.

That’s really weird.

Do these projects use any plugins? If so, which ones?

Could you test on your server if the same happens with a fresh Kirby Starterkit?

i can try! it will take me some time as i’m new to kirby, i just help administrate this server. someone else built the sites.

they both use the kirby3-srcset plugin, that’s it.

any other simple tips for exploration/debugging?

Could you post what config options are set for this plugin? Or the config for one of the projects in general if it doesn’t contain any secrets like API keys etc.? If there is more than one config file, then all config files.

What I’m particularly looking for is a debug mode setting for the plugin.

the config for one:

<?php
return [
'debug'  => true,
  'panel' =>[
  'install' => true
  ],

'thumbs' => [
    'srcsets' => [
      'default' => [
        '800w' => ['width' => 800, 'quality' => 80],
        '1024w' => ['width' => 1024, 'quality' => 80],
        '1440w' => ['width' => 1440, 'quality' => 80],
        '2048w' => ['width' => 2048, 'quality' => 80]
      ]
  ]
  ]
];
?>

and for the other:

<?php
return [
'debug'  => true,
  'panel' =>[
  'install' => true
  ],


'thumbs' => [
    'srcsets' => [
      'default' => [
        '800w' => ['width' => 800, 'quality' => 80],
        '1024w' => ['width' => 1024, 'quality' => 80],
        '1440w' => ['width' => 1440, 'quality' => 80],
        '2048w' => ['width' => 2048, 'quality' => 80]
      ]
  ]
  ],

  'markdown' => [
    'extra' => true
  ]
];

?>

previously, i have tried changing ‘debug’ to false. i didn’t notice any difference.

Debug should always be set to false on a production server, but if setting this to false doesn’t have any effect regarding the thumbs, then maybe the plugin doesn’t do anything different depending on that mode, I didn’t really study the source code thoroughly.

This setting should also always be set to false on production, but has nothing to do with the issue, just a security thing.

I currently have no other ideas, if that is all in the configs and there are no other plugins. but if you have the time, try to install a fresh Starterkit and check if that behaves as it should.

It usually just a matter of copying the files over to a server. The only thing that we don’t provide is the nginx config that corresponds to what is in the default .htaccess, but you should be able to use that from the other projects.

Which reminds me that it might be worth looking into this config and if it has any settings that might interfere with the thumbs.

Related:

so i’ve setup a fresh subdomain, git cloned the kirby starterkit, and used the same nginx config from the ‘problematic’ sites.

it’s the same problem! if you’re curious, here are the inotifywait log entries:

2020-11-28 21:11:09 html/media/pages/photography/ CREATE,ISDIR trees
2020-11-28 21:11:09 html/media/pages/photography/sky/2ceebcac58-1606594230/ CREATE,ISDIR .jobs
2020-11-28 21:11:09 html/media/pages/photography/ CREATE,ISDIR ocean
2020-11-28 21:11:09 html/media/pages/photography/ CREATE,ISDIR desert
2020-11-28 21:11:09 html/media/pages/photography/ CREATE,ISDIR mountains
2020-11-28 21:11:09 html/media/pages/photography/ CREATE,ISDIR waterfall
2020-11-28 21:11:09 html/media/pages/photography/ CREATE,ISDIR plants
2020-11-28 21:11:09 html/media/pages/photography/ CREATE,ISDIR landscape
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ CREATE monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ MODIFY monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ MODIFY monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ MODIFY monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ MODIFY monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ MODIFY monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ MODIFY monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/trees/a8f5717c16-1606594230/ DELETE monster-trees-in-the-fog-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/sky/2ceebcac58-1606594230/ CREATE dark-forest-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/sky/2ceebcac58-1606594230/ MODIFY dark-forest-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/sky/2ceebcac58-1606594230/ DELETE dark-forest-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/ocean/1acbc789ab-1606594230/ CREATE island-from-above-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/ocean/1acbc789ab-1606594230/ MODIFY island-from-above-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/ocean/1acbc789ab-1606594230/ DELETE island-from-above-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/desert/dd56ce6cf4-1606594230/ CREATE indiana-jones-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/desert/dd56ce6cf4-1606594230/ MODIFY indiana-jones-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/desert/dd56ce6cf4-1606594230/ MODIFY indiana-jones-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/desert/dd56ce6cf4-1606594230/ MODIFY indiana-jones-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/desert/dd56ce6cf4-1606594230/ MODIFY indiana-jones-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/desert/dd56ce6cf4-1606594230/ DELETE indiana-jones-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/mountains/c4ae6b8819-1606594230/ CREATE probably-photoshopped-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/mountains/c4ae6b8819-1606594230/ MODIFY probably-photoshopped-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/mountains/c4ae6b8819-1606594230/ DELETE probably-photoshopped-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ CREATE the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ MODIFY the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/waterfall/3197ffb196-1606594230/ DELETE the-fall-is-lava-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/plants/326f817b2e-1606594230/ CREATE nice-colors-ugly-plant-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/plants/326f817b2e-1606594230/ MODIFY nice-colors-ugly-plant-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/plants/326f817b2e-1606594230/ MODIFY nice-colors-ugly-plant-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/plants/326f817b2e-1606594230/ MODIFY nice-colors-ugly-plant-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/plants/326f817b2e-1606594230/ MODIFY nice-colors-ugly-plant-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/plants/326f817b2e-1606594230/ MODIFY nice-colors-ugly-plant-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/plants/326f817b2e-1606594230/ DELETE nice-colors-ugly-plant-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/landscape/94a6b721bf-1606594230/ CREATE that-green-looks-fake-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/landscape/94a6b721bf-1606594230/ MODIFY that-green-looks-fake-1024x1024.jpg
2020-11-28 21:11:09 html/media/pages/photography/landscape/94a6b721bf-1606594230/ DELETE that-green-looks-fake-1024x1024.jpg

i’ve checked timestamps on the original files in content/ and nothing looks unusual to me…

one strange thing is that there’s currently one survivor jpg in media/:

media/pages/photography/sky/2ceebcac58-1606594230/dark-forest.jpg

this was created as i was troubleshooting permission issues while getting things running (at first media didn’t have write permissions. after fixing it, i requested the URL to the above image to test)

so it appears to only be suiciding scaled images.

yeah, i just isolated the URL to a scaled image in the starterkit. when i request it - it’s created and served - but then immediately deleted.

ok i’m making a bit of progress.

it turns out that requests to scaled images are just returning the originals. i did an md5sum comparison

i suspected this after finding the following code in src/Cms/Media.ph:

        try {
            $kirby->thumb($source, $thumb, $options);
            F::remove($job);
            return Response::file($thumb);
        } catch (Throwable $e) {
            F::remove($thumb);
            return Response::file($source);
        }

ok, i figured it out. the php-gd extension simply wasn’t installed! is there a quicker way i could have caught this? like, are the exceptions logged anywhere?

Good question, I was under the impression that the thumbs were getting created, because without gd, only the originals would ever be copied and no thumbs created.

well, i came at this problem from a very unusual angle. most people would never see that the thumb files are technically being created, i just happened to be closely monitoring the filesystem (for completely unrelated reasons).

Yes, you are right, if the developer doesn’t check they really get the expected result, then the error might go unnoticed, because instead of throwing an error, the not-real-thumbs are silently removed. Guess that is so that the site continues to work even if no thumbs are generated.

GD or ImageMagick are a server requirement though for Kirby to work, so developers should make sure that a server meets these requirements before putting things out to a production server.

seems strange that it doesn’t throw an error when debug is true, though.

Its odd that GD wasnt installed, this is usually the default for most hosts. Is this typical off the shelf hosting, or something you put together urself, like a VPS or something? I find IM gives better results in most cases but its odd that GD was missing.