Original Post
I'm currently writing the backbone for a small Internet BBS system in PHP4 with MySQL. This backbone is supposed to be quite generic, only handling logins, rights checking and authentication, really.' The goal is to have another module provide the actual BBS functionality, but also allow for adding blogging, CMS, project management, and other things which might require authentication, to a site using this common login system. As such, I need to keep permissions quite generic. However, I'm having a little trouble with how I should make sure rights checking doesn't completely bog down the web server that runs it. Currently, this is the way I've conceived rights checking: Users are members of zero or more groups. Groups are assigned rights to resources. Group memberships are stored in a table where each item consists of a group ID, a user ID and a unique membership ID. Groups' rights to resources are stored in a table where each item consists of a group ID, a resource ID and the rights the group has to the resource. When a user wants to access a resource, a function auth_is_allowed is called with the users ID, the object's ID and the right the user has requested (for example, R_READ). Now, this function has to first figure out all of the user's memberships. This can be done with a single SQL query and isn't that bad. However, after this the permissions need to be checked for every group the user is a member of, with either a query for each one, or a long "SELECT rights FROM rights_table WHERE (group_id='2' OR group_id='7' OR ...) AND resource_id='blah'". Either way, it seems to me that the SQL server, the web server or both will be doing a lot of work if the user is a member of a lot of groups. I've thought of caching the user's permissions to all object he has previously accessed in a $_SESSION variable and only update them when they change, but I'm not too sure about the feasibility of the idea. Should I try to optimise this, or is the overhead of the queries too small to bother? If I should, do you have any suggestions as to how? Is there a better way altogether that I haven't thought of? EDIT: I can grammar.