0

I know the standard way to check user roles mostly like if(isUserAuthorizedForTheOperation(userId)) in PHP which is create a db and for every user check the db and find out.Now this adds to immense performace issues.For every hit in my .php file,I find it extremly costly to query the database.What is the alternative?

a YUY
  • 87
  • 9
  • 1
    Could you document precisely what the performance problem is? We can't guess your volume or offer even rudimentary advice with so little concrete evidence of an actual problem in some aspect of system performance. – bmike Jan 21 '15 at 17:28
  • You could just get the list of roles the user has and save it in the session, then you only have one database lookup. – dave Jan 21 '15 at 17:29
  • @dave thanks for the suggestion.Your approach would surely save me from making multiple calls – a YUY Jan 21 '15 at 17:34
  • @CamilStaps thanks for the suggestion.It answeres my question – a YUY Jan 21 '15 at 17:35

1 Answers1

0

Do you perform one query per hit/session or multiple? Make sure you only load in the roles once, store it in a (session) variable, and then keep checking that variable - instead of performing a query for every time you want to check.

(Taken from the comments as OP said it answered his question.)