yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

yii\rbac\PhpManager and OPcache issue #9948

Closed flowip closed 8 years ago

flowip commented 9 years ago

If you use PhpManager and OPcache is enabled and opcache.revalidate_freq is not zero (2 seconds by default), then after assigning a user to a role there is gonna be 2 seconds interval when PhpManager will return old roles for a user. But only in next user requests, because assignments not only stored in assignments.php file, but also in $this->assignments array.

So, if you assign new role to a user on login and then redirect him to some page, then this page will not know that the user is assigned to a new role, because old (cached) assignments.php file will be returned.

My workaround. I call opcache_invalidate($auth->assignmentFile) after assigning new roles to users.

flowip commented 8 years ago

In my opinion it's a bug, not enhancement or feature.

samdark commented 8 years ago

Besides opcache there are XCache, APC and more PHP opcode cachers. I don't think it's in the framework scope to invalidate their data.

cebe commented 8 years ago

I think it should be added.

samdark commented 8 years ago

For which cache backends?

cebe commented 8 years ago

just opcache because it is built into php. APC is kind of outdated. XCache does not have such a function as far as I see.

samdark commented 8 years ago

OpCache is built into PHP 5.5+ but for PHP 5.4 it's common to use APC. Since we're supporting 5.4+ for 2.0, I'm not sure it's a good idea to have code for OpCache only.

SilverFire commented 8 years ago

We've agreed to support only 5.6+ since 2.1. I don't think it's a problem

cebe commented 8 years ago

then lets add apc for 2.0.x too. http://php.net/manual/en/function.apc-delete-file.php

samdark commented 8 years ago

OK.

klimov-paul commented 8 years ago

Resolved by commit b7b8348c732065aa2c41f0775ed3450afbe9097e