# clearstatcache change

- Thread: https://externals.io/message/39693
- Original archive: https://news-web.php.net/php.internals/39693
- Started by Rasmus Lerdorf on 2008-08-06T10:28:21+00:00
- Messages: 11
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #39693 — Rasmus Lerdorf — 2008-08-06T10:28:21+00:00

URL: https://externals.io/message/39693#39693

I think we either need to make `clearstatcache()` not affect the realpath 
cache, or we should add an optional argument to it to specify whether or 
not the realpath cache should be cleared as well.

The realpath cache makes a huge difference on includes and having the 
cache blown away by a script calling `clearstatcache()` really hurts. In 
almost all cases the script is doing it to clear the stat cache for some 
local file it is doing stuff to and the author has no idea that she is 
blowing away the realpath_cache as well.  And if that script is run on 
every request, the realpath_cache becomes completely useless.

-Rasmus

---

## #39703 — Jani Taskinen — 2008-08-06T16:18:49+00:00

URL: https://externals.io/message/39693#39703 · In reply to: #39693

Rasmus Lerdorf wrote:
> I think we either need to make `clearstatcache()` not affect the realpath 
> cache, or we should add an optional argument to it to specify whether or 
> not the realpath cache should be cleared as well.

See this: http://bugs.php.net/39367

Considering some people seem to want to clear realpath cache as well, I'd make 
it an optional parameter which defaults to NOT clear realpath cache:

clearstatchache(true); /* BOOM! realpath cache gone.. */

btw. I just noticed chroot() calls this realpath_cache_clean()..intentional?
Also some streams stuff uses the php_clear_stat_cache() func but those should 
propably use the realpatch_cache_del() instead and not blow away whole cache?

Here is a patch to add that optional parameter (for PHP_5_3):

http://pecl.php.net/~jani/patches/clearstatcache_optional_param.patch

--Jani

---

## #39708 — Arnaud Le Blanc — 2008-08-06T17:56:58+00:00

URL: https://externals.io/message/39693#39708 · In reply to: #39703

Hi,

On Wednesday 06 August 2008 18:18:49 Jani Taskinen wrote:
> Rasmus Lerdorf wrote:
> > […]
>
> See this: http://bugs.php.net/39367
>
> Considering some people seem to want to clear realpath cache as well, I'd
> make it an optional parameter which defaults to NOT clear realpath cache:
>
> clearstatchache(true); /* BOOM! realpath cache gone.. */
>
> btw. I just noticed chroot() calls this
> realpath_cache_clean()..intentional? Also some streams stuff uses the
> php_clear_stat_cache() func but those should propably use the
> realpatch_cache_del() instead and not blow away whole cache?

Yes, I think too.
I added that to your patch: 
http://arnaud.lb.s3.amazonaws.com/clearstatcache_optional_params.patch :) 

It also adds the "filename" argument to 
clearstatcache([bool clear_realpath_cache[, filename]])

>
> Here is a patch to add that optional parameter (for PHP_5_3):
>
> http://pecl.php.net/~jani/patches/clearstatcache_optional_param.patch
>
> --Jani

---

## #39712 — Arnaud Le Blanc — 2008-08-06T19:00:59+00:00

URL: https://externals.io/message/39693#39712 · In reply to: #39708

On Wednesday 06 August 2008 19:56:58 Arnaud Le Blanc wrote:
> Hi,
>
> On Wednesday 06 August 2008 18:18:49 Jani Taskinen wrote:
> > […]
>
> Yes, I think too.
> I added that to your patch:
> http://arnaud.lb.s3.amazonaws.com/clearstatcache_optional_params.patch :)
>
> It also adds the "filename" argument to
> clearstatcache([bool clear_realpath_cache[, filename]])

I reply to myself, actually this may cause troubles to not clear the full 
cache in plain_wrapper.c :/ I updated the patch, just left the filename 
argument to `clearstatcache()`.

>
> > […]

---

## #39716 — Hannes Magnusson — 2008-08-06T21:15:57+00:00

URL: https://externals.io/message/39693#39716 · In reply to: #39712

> On Wednesday 06 August 2008 19:56:58 Arnaud Le Blanc wrote:
> > […]
>
> I reply to myself, actually this may cause troubles to not clear the full
> cache in plain_wrapper.c :/ I updated the patch, just left the filename
> argument to `clearstatcache()`.

Don't forget to update the arginfo

-Hannes

---

## #39720 — johannes@php.net — 2008-08-06T23:50:06+00:00

URL: https://externals.io/message/39693#39720 · In reply to: #39712

> > […]

I'd assume that, as /foo inside a chroot is different from /foo
outside...

>  Also some streams stuff uses the
> > […]
> 
> I reply to myself, actually this may cause troubles to not clear the full 
> cache in plain_wrapper.c :/ I updated the patch, just left the filename 
> argument to `clearstatcache()`.

If you fix the arginfo like Hannes it's, good. If the name of the second
parameter in the proto ("filename") is the same as in the implementation
("pathname") it might even be a bit better :-)

johanes

---

## #39727 — Arnaud Le Blanc — 2008-08-07T09:33:02+00:00

URL: https://externals.io/message/39693#39727 · In reply to: #39720

On Thursday 07 August 2008 01:50:06 Johannes Schlüter wrote:
> 
> > […]
>
> I'd assume that, as /foo inside a chroot is different from /foo
> outside...
>
> > […]
>
> If you fix the arginfo like Hannes it's, good. If the name of the second
> parameter in the proto ("filename") is the same as in the implementation
> ("pathname") it might even be a bit better :-)
>
> johanes

Commited :)

---

## #39796 — Arnaud Le Blanc — 2008-08-09T14:20:31+00:00

URL: https://externals.io/message/39693#39796 · In reply to: #39727

On Thursday 07 August 2008 11:33:02 Arnaud Le Blanc wrote:
> On Thursday 07 August 2008 01:50:06 Johannes Schlüter wrote:
> > […]
>
> Commited :)


Hi,

I have noticed that there is no function to know the realpath cache usage 
(e.g. is the realpath cache full ? what files are in the cache ?)

I have written two functions:
realpath_cache_get_entries() which returns an array of entries in the cache, 
and realpath_cache_get_usage() which returns the cache size. The first one may 
also help in writing tests for the realpath cache.

http://arnaud.lb.s3.amazonaws.com/realpath_cache_funcs.patch

Can I add them ?

Regards,

Arnaud

---

## #39808 — Pierre Joye — 2008-08-10T15:14:52+00:00

URL: https://externals.io/message/39693#39808 · In reply to: #39796

hi Arnaud!



> > […]

Do you have a windows dev box? It seems that something is broken on
Windows. One reproduce case is
ext\standard\tests\file\copy_variation4-win32.phpt which fails using
current 5.3-cvs.

Let me know if you do not have a win box, I can try to fix it later this week.

Cheers,
-- 
Pierre

http://blog.thepimp.net | http://www.libgd.org

---

## #39810 — Arnaud Le Blanc — 2008-08-10T15:46:20+00:00

URL: https://externals.io/message/39693#39810 · In reply to: #39808

On Sunday 10 August 2008 17:14:52 Pierre Joye wrote:
> hi Arnaud!
>
> 
> > […]
>
> Do you have a windows dev box? It seems that something is broken on
> Windows. One reproduce case is
> ext\standard\tests\file\copy_variation4-win32.phpt which fails using
> current 5.3-cvs.
>
> Let me know if you do not have a win box, I can try to fix it later this
> week.
>
> Cheers,

Hi Pierre,

No, I do not have a windows box here.
Does this test pass without this change ? http://news.php.net/php.cvs/52079

Regards,

Arnaud

---

## #39811 — Arnaud Le Blanc — 2008-08-10T16:11:14+00:00

URL: https://externals.io/message/39693#39811 · In reply to: #39810

On Sunday 10 August 2008 17:46:20 Arnaud Le Blanc wrote:
> On Sunday 10 August 2008 17:14:52 Pierre Joye wrote:
> > […]
wrote:
> > […]
>
> Hi Pierre,
>
> No, I do not have a windows box here.
> Does this test pass without this change ? http://news.php.net/php.cvs/52079
>
> Regards,
>
> Arnaud

Just readden the test, actually it seems it just needs to be updated (changing 
 `clearstatcache()` by clearstatcache(true)).

Regards,

Arnaud
