# Image (Resize, Crop, ...) doesn't use previous generated files

**URL:** <https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436>\
**Category:** Questions\
**Tags:** v2\
**Created:** [January 28, 2017, 9:42am UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436 "2017-01-28T09:42:46Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [January 30, 2017, 1:49pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/21 "2017-01-30T13:49:40Z")

</div>

I’ve created an[issue on GitHub.](https://github.com/getkirby/kirby/issues/546)

---

<div class="post-metadata">

**Author:** ![robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@robert](https://forum.getkirby.com/u/robert)\
**Post date:** [January 30, 2017, 1:53pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/22 "2017-01-30T13:53:16Z")

</div>

Is there a workaround possible, till this issue is solved?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [February 3, 2017, 12:29pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/23 "2017-02-03T12:29:46Z")

</div>

`call_user_func_array` [seems to be slow when called often or with too many arguments](https://gist.github.com/nikic/6390366). one could refactor the function `toolkit/helper/call()` to use [argument unpacking (since php 5.6)](http://php.net/manual/en/migration56.new-features.php). so instead of `call_user_func_array` use something like that:

```
$object->{$method}(...$args);

```

or when no object available

```
$method(...$args);
```

---

<div class="post-metadata">

**Author:** ![robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@robert](https://forum.getkirby.com/u/robert)\
**Post date:** [February 3, 2017, 1:40pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/24 "2017-02-03T13:40:45Z")

</div>

I tried this before, but it changed nothing. It stays slow as it was before.

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [February 3, 2017, 2:01pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/25 "2017-02-03T14:01:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [June 17, 2017, 6:56pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/26 "2017-06-17T18:56:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Andi-Lo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/andi-lo/32/2582_2.png) [@Andi-Lo](https://forum.getkirby.com/u/Andi-Lo)\
**Post date:** [June 19, 2017, 3:56pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/27 "2017-06-19T15:56:34Z")

</div>

@lukasbestle drop me a pm and we discuss things further.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [June 19, 2017, 5:32pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/28 "2017-06-19T17:32:16Z")

</div>

Feel free to send me one with more information. You can also drop me an email at lukas@getkirby. Thanks. 🙂

---

<div class="post-metadata">

**Author:** ![robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@robert](https://forum.getkirby.com/u/robert)\
**Post date:** [June 20, 2017, 2:11pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/29 "2017-06-20T14:11:14Z")

</div>

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

After a hint in another post ([Super slow frontend and panel not loading at all](https://forum.getkirby.com/t/super-slow-frontend-and-panel-not-loading-at-all/6776/10)), I changed von PHP 7 back to 5.6 and activated fast-cgi.

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.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [June 21, 2017, 4:22pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/30 "2017-06-21T16:22:00Z")

</div>

@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…

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [June 21, 2017, 7:48pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/31 "2017-06-21T19:48:35Z")

</div>

What @anon77445132 wrote is correct. Starting up a PHP worker takes a lot of time (a few seconds), so if there is none because there haven’t been requests in a while, it’s normal for the first page load to be slower. And because that startup time is spent before Kirby is even loaded, we can’t do anything against that.

What you could try to verify if this worker timeout is the issue:

1. Load a page with many thumbs, note down the response time.
2. Load the page again, note down the response time.
3. Wait for a “longer period”.
4. Load a page that _doesn’t_ have _any_ thumbs and note down the response time.

If the page without thumbs takes long to load as well, it can’t be related to thumbs.

---

<div class="post-metadata">

**Author:** ![robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@robert](https://forum.getkirby.com/u/robert)\
**Post date:** [June 22, 2017, 4:42am UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/32 "2017-06-22T04:42:01Z")

</div>

@lukasbestle @anon77445132 No, it’s not the starting up of a PHP worker:  
The concrete website is hosted at a provider and starts with a login-page - without any image. This login-page comes as fast as it should. The website is a gallery of a approx. hundred of images. This gallery is paginated, so that on every page a dozen of images are shown. The long loads are on every new (paginated) page. When a page is reloaded the loads are very quick.

To mention it explicit: The load times are measured on server side.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [June 22, 2017, 4:26pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/33 "2017-06-22T16:26:40Z")

</div>

@robert:  
Does the website or your hoster use any cache or CDN?  
Does your browser use any add-in that shows something like a cache?  
Have you changed your `/site/config/config.php` to use the Kirby cache or another cache or CDN?

---

<div class="post-metadata">

**Author:** ![robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@robert](https://forum.getkirby.com/u/robert)\
**Post date:** [June 23, 2017, 7:34am UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/34 "2017-06-23T07:34:21Z")

</div>

Answer to all questions: No

The only cache that’s enabled is the opcache-module of PHP.

---

<div class="post-metadata">

**Author:** ![anon77445132](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@anon77445132](https://forum.getkirby.com/u/anon77445132)\
**Post date:** [June 23, 2017, 4:24pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/35 "2017-06-23T16:24:39Z")

</div>

I would look at the …

> [@robert](#):
>
> opcache-module of PHP

May be, stop the opcache-module for a test and look for your error, is this error gone?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [June 23, 2017, 7:52pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/36 "2017-06-23T19:52:40Z")

</div>

Thanks for the details. I agree that it can’t be the worker processes then. I’d also rule out the OpCache as that only caches the code files, not any type of generated content.

But the issue is still strange. I don’t know where to start debugging as I can’t reproduce it. 🙁

---

<div class="post-metadata">

**Author:** ![robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@robert](https://forum.getkirby.com/u/robert)\
**Post date:** [June 24, 2017, 5:56am UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/37 "2017-06-24T05:56:33Z")

</div>

@anon77445132 Deactivating the opcache-module results only in slower overall performance of execution of kirby.

@lukasbestle As mentioned in my post from [2017-01-30](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/20) there seems to be a problem with the execution of `call_user_func_array($function, $arguments)` in `toolkit/helpers.php`. The calls results in slow “first time execution” for the image-objects. Maybe this is an PHP-internal effect?!

Theoretically, the execution of `call_user_func_array()` was optimized in PHP7, but in this case it is not faster.

As I have not enough PHP-knowledge, I’m not able to further investigate the specific calls, which are executed during getting/preparing an image.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [June 24, 2017, 8:36pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/38 "2017-06-24T20:36:30Z")

</div>

I can’t be `call_user_func_array()`, especially not because we use this function (with Kirby’s `call()` helper) a lot, not only for thumbs.

But of course `call_user_func_array()` calls a function and that function might/will be the bottleneck (or some other function that is called by that function). However we don’t know where to start debugging if we can’t reproduce the issue.

---

<div class="post-metadata">

**Author:** ![robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@robert](https://forum.getkirby.com/u/robert)\
**Post date:** [June 30, 2017, 1:24pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/39 "2017-06-30T13:24:11Z")

</div>

@lukasbestle Is there a way to produce a log (including timing) with “all” inner-calls for `call_user_func_array()`? I’m not that familiar with PHP, so I need assistance to do that. After that I can give you the resulting log-file.

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [June 30, 2017, 1:49pm UTC](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436/40 "2017-06-30T13:49:21Z")

</div>

That’s a good idea. You can use [Xdebug’s Profiler](https://xdebug.org/docs/profiler) for this.

[Previous page](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436.md?page=1)

[Next page](https://forum.getkirby.com/t/image-resize-crop-doesnt-use-previous-generated-files/6436.md?page=3)
