title: Large PHP session slowing down web application
body: <p>I have a web application where complex permissions determine whether or not a user has access to each of thousands of different files. A user can see all files, but there is an indicator to open files that they have access to. A user has access to a file if someone else in their organization has access to it, or if someone that they are in a collaboration with has shared access to that file. </p>
  
  <p>Right now, I have a complex PHP function that generates a large PHP session by building arrays of the files a user has access to, either in their organization or their collaborations, and merging these access arrays. When these files are displayed to the user, PHP checks this array to see if they have access, and if they do, it adds the button to open the file. I am doing it this way because running the query to check for access for each individual file ended up taking way too long when displaying long file lists, and PHP's in_array() was substantially faster.</p>
  
  <p><strong>The problem is...</strong></p>
  
  <p>The php session has gotten so large that it seems to be slowing down simple website functions to a crawl, and I need to think of a new way to do this. </p>
  
  <p><strong>My question is...</strong></p>
  
  <p>What would be the best way to replace PHP sessions for storing file permissions and file locations for thousands of files a user has access to, so that when lists of files are being displayed, PHP can rapidly retrieve this information, without needing to run a query for each individual file?</p>