Because the execution of the commands crop or resize takes some 1000-10000 ms. When the thumbs are loaded from thumbs-folder, the execution lasts only a view ms (3-4).
As I mentioned before, the files in the thumbs-folder are staying unchanged (size, timestamp).
I guess you could just put in a dump() command in the source code or log something to file to see if the isThere() check is true and the thumb newly created. I canāt really believe that the thumb is just overwritten without the time stamp being modified. Even if I set the overwrite option to true, so that the thumb is always recreated, the modified timestamp gets changed.
I donāt think it works like that, the thumb method does not return an object of type Thumb, but of type Media. What I meant was to dump something directly in the thumb constructor in the source code (in kirby/vendor/getkirby/toolkit/lib/thumb.php)
OK, I put an echo into the constructor for type Thumb, and it reports that the thumbs already exists and they were not created again. Thatās fine.
But the problem still exists that it lasts sometimes multiple seconds to get the thumb after a resize or crop. Any idea?
Edit: To ensure that the server does not respond too slow for checking the existence of the thumb, I included a stopwatch. The execution time of isThere is 0 ms.
Yes, it seems to be a similar problem. The difference is, that my website is online and runs with Linux/Apache. For image processing I use imagick.
As I mentioned before, this effect occurs randomly. When the website is not used (for a few hours), this effect occurs. But when a page was loaded, a reload is fast as it should be.
After a little bit more investigation, the code which causes this behaviour is in kirby/component/thumb.php in the function public function create($file, $params):
$thumb = new Generator($file, $params);
My experience in PHP is two weak to further follow the problem. Has anyone a suggestion?
With analysing the runtime of commands, I was able to identify the position where the starting-point of this problem is. The call-sequence to the starting-point is:
...->image()->crop(...)
traits/image.php:
public function crop() ->
public function thumb(): return $this->kirby->component('thumb')->create($this, $params);
component/thumb.php:
public function create(): $thumb = new Generator($file, $params);
toolkit/lib/thumb.php:
public function __construct(): $this->destination = $this->destination(); ->
public function destination(): $result = call($this->options['destination'], $this);
toolkit/helpers.php:
function call(): call_user_func_array($function, $arguments)
And exactly the call of call_user_func_array($function, $arguments) causes this problem.
then refactor panel/models/page/removeThumbs() to not clean folder but check for timestamp of all thumb-files if page panel/models/page/replace() and upload() where called. if move() was called it needs to remove all.
Unfortunately I canāt reproduce this issue. I have tried generating several thumbs of an image. First page load takes around 3 seconds, every following page load around 3 milliseconds.
@robert@Andi-Lo Do you have a simple test-case based on the starterkit that is able to reproduce this issue?
@lukasbestle As you mentioned, the first load took ā3 secondsā, the following page load around ā3 millisecondsā. When you wait a while (a longer period), the next page load again lasts ā3 secondsā - then the next page load ā3 millisecondsā - and so on. (The āsecondsā depends on the host, which is running the scripts)
This helped in that way, that the (first) load of the pictures lasts only a tenth of the time required before. But the first load of one (!) picture (of a dozen on this page) requires still approx. 500 milliseconds.
@robert:
Are you sure, that the PHP process runs 24 h a day?
On some cheap installations, the PHP process dies after some time of not running. The PHP process then needs to start for the āfirstā webpage, what needs some time. The next webpage is very much fasterā¦