# File system cache clearByTags sometimes crash with file/directory error

**URL:** <https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805>\
**Category:** Components & MVC\
**Tags:** laminas-cache\
**Created:** [March 10, 2022, 10:47am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805 "2022-03-10T10:47:16Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 10, 2022, 10:47am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/1 "2022-03-10T10:47:16Z")

</div>

Hello,

I’m using the Laminas Cache component with the filesystem adapter (and plugin serializer).  
Here is what I use to initialize my cache object :

```auto
\Laminas\Cache\StorageFactory::factory
							(
								array
								(
									'adapter'	=>
										[
											'name' =>	'filesystem',
											'options'	=>
												[
													'namespace' => 'My Name Space',
													'cache_dir' => '/my/cache/directory'
												]
										],
									'plugins'	=>	['serializer']
								)
							)

```

Sometimes (not always !) I’ve got file/directory error when I call the “clearByTags” method (with an array of few tags and disjunction to true), like :  
`[09-Mar-2022 17:29:49 Europe/Paris] PHP Fatal error: Uncaught ErrorException: rmdir(/home/web/variance-auto.com/www/site/temporaire/cache/outils/luminis-f3): The directory isn't empty in /my/directory/vendor/laminas/laminas-cache-storage-adapter-filesystem/src/Filesystem.php:110`  
or  
`[10-Mar-2022 09:23:30 Europe/Paris] PHP Fatal error: Uncaught ErrorException: unlink(/my/directory/cache/outils/label-ac/label-111853527cf9967b9d6c81d2396ec04c.tag): No such file or directory in /my/directory/vendor/laminas/laminas-cache-storage-adapter-filesystem/src/Filesystem.php:1658`

Is that a known issue ? How can I fix it, please ?

Thanks for your precious helps.

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 10, 2022, 1:20pm UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/2 "2022-03-10T13:20:06Z")

</div>

Can you test the version 2 of this cache adapter? There are some reworks of the interaction with the file system.

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 10, 2022, 3:26pm UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/3 "2022-03-10T15:26:59Z")

</div>

Hello @froschdesign ! thanks for your reply.  
Are you talking about the filesystem component version or the cache component version ?  
Here is the version in use on my env :

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/2X/3/3aab7551ef692f8067676bc31217e2ec049e77ff.png)

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 10, 2022, 6:38pm UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/4 "2022-03-10T18:38:33Z")

</div>

I mean the cache adapter `Filesystem` but I see you use the older version 2 of laminas-cache and this means you can only use the version 1 of the `Filesystem` adapter.

Maybe you can test version 3 of laminas-cache and the `Filesystem` adapter with version 2 on your system.

* * *

By the way: You do not have to install all cache adapters, check the [installation description](https://docs.laminas.dev/laminas-cache/v2/installation/#avoid-unused-cache-adapters-are-being-installed) for this.

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 11, 2022, 3:07pm UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/5 "2022-03-11T15:07:08Z")

</div>

Thanks for all of this @froschdesign !  
Install OK !

 ![image](https://canada1.discourse-cdn.com/flex032/uploads/zendframework/original/2X/9/9037781bae119574475abfd90a4abbbf64e10df3.png)

I’ll make some tests and give a feedback about how it fix or not the problem.

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 17, 2022, 8:37am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/6 "2022-03-17T08:37:08Z")

</div>

Hello !

Sadly, updating to the latest version doesn’t seems to fix it : the error happen again :’(.

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 17, 2022, 8:55am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/7 "2022-03-17T08:55:27Z")

</div>

> [@nvincent](#):
>
> the error happen again

What does the error message actually look like?

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 17, 2022, 9:13am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/8 "2022-03-17T09:13:18Z")

</div>

@froschdesign same as previously.  
There is CHMOD, UNLINK or RMDIR problem.  
Here is an example :  
`[17-Mar-2022 05:02:49 Europe/Paris] PHP Fatal error: Uncaught ErrorException: rmdir(/my/directory/cache/outils/luminis-ac): Directory is not empty in /my/directory/vendor/laminas/laminas-cache-storage-adapter-filesystem/src/Filesystem.php:173`

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 17, 2022, 9:17am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/9 "2022-03-17T09:17:50Z")

</div>

Have you tried to set the permissions yourself? This can be done via adapter options:

> **[Adapters - laminas-cache - Laminas Docs](https://docs.laminas.dev/laminas-cache/v3/storage/adapter/#adapter-specific-options_2)**
>
> Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output.

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 18, 2022, 11:38am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/10 "2022-03-18T11:38:08Z")

</div>

Not sure about what you mean : changing “dir\_permission/file\_permission” value on my own ?  
If yes, I’m not sure that’s the problem as much of case works pretty well currently. If it’s a permission problem, it shall never work, right ?

Dunno if it could help but I realize it happen kinda only on long execution time script…

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 18, 2022, 11:44am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/11 "2022-03-18T11:44:25Z")

</div>

> [@nvincent](#):
>
> If it’s a permission problem, it shall never work, right ?

Right, forget my last comment on that. I hadn’t remembered that the problem doesn’t always occur.

> [@nvincent](#):
>
> Dunno if it could help but I realize it happen kinda only on long execution time script…

Could the problem be concurrent queries?

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 21, 2022, 9:11am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/12 "2022-03-21T09:11:29Z")

</div>

Hello @froschdesign !

Hm, it could be yes… how can I verify if it is concurent queries ?

Others examples of error I get in log (without stack trace - translated from french) :

```auto
[19-Mar-2022 05:01:13 Europe/Paris] PHP Fatal error: Uncaught ErrorException: rmdir(/my/directory/cache/outils/luminis-c5): directory is not empty /my/directory/vendor/laminas/laminas-cache-storage-adapter-filesystem/src/Filesystem.php:173
[19-Mar-2022 22:14:40 Europe/Paris] PHP Fatal error: Uncaught ErrorException: fopen(/my/directory/cache/outils/luminis-ac/luminis-111853527cf9967b9d6c81d2396ec04c.dat): failed to open stream: no file/directory of the type in /my/directory/vendor/laminas/laminas-cache-storage-adapter-filesystem/src/Filesystem/LocalFilesystemInteraction.php:172

```

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 22, 2022, 2:25pm UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/13 "2022-03-22T14:25:29Z")

</div>

And another one (without stack trace - translated from french) :  
`[21-Mar-2022 18:17:18 Europe/Paris] PHP Fatal error: Uncaught ErrorException: chmod(): no file/directory of this type in /my/directory/vendor/laminas/laminas-cache-storage-adapter-filesystem/src/Filesystem/LocalFilesystemInteraction.php:153`

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [March 29, 2022, 2:44pm UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/14 "2022-03-29T14:44:26Z")

</div>

Any other ideas about this, please ? Anyone ?

---

<div class="post-metadata">

**Author:** ![nvincent](https://avatars.discourse-cdn.com/v4/letter/n/5f9b8f/32.png) [@nvincent](https://discourse.laminas.dev/u/nvincent)\
**Post date:** [April 13, 2022, 7:45am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/15 "2022-04-13T07:45:17Z")

</div>

Still pending… shall I open a issue on the project (that’s a real question ^^) ?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 13, 2022, 8:47am UTC](https://discourse.laminas.dev/t/file-system-cache-clearbytags-sometimes-crash-with-file-directory-error/2805/16 "2022-04-13T08:47:12Z")

</div>

Try to ask in the [Chat](https://getlaminas.org/participate/).
