Or Arbel
Or Arbel

Reputation: 2975

PHP MySQL - Calculating scores according to users actions from MySQL DB

I have a website the users can do stuff like leave comments, perform likes, etc..
I want to calcluate a score for each user that is composed from these actions, i.e: Like = 10 points, comment = 20 points etc..

I would like to create a table with users score that will be calculated once a day.

Currently i use a php script and execute, but it takes too long to calculate and then it times-out..

whats the method for perfomring this?

Upvotes: 1

Views: 184

Answers (2)

rkmax
rkmax

Reputation: 18133

basically what you do is add a record of what the user in your web application, instead of calculating every batch, you can:

  1. save each action along with its own score and then with a simple query that you do every day, update the user's score
  2. keep independent of each action, you can directly add up the score every day user

TIP

as you have planned to update the score every day user can add a cache for a long duration so that the query does not harm performance

Upvotes: 1

Christofer Eliasson
Christofer Eliasson

Reputation: 33865

How long time does the script take?

If you just want to increase the amount of time the script is allowed to take to execute, you can make use of PHP's set_time_limit() to increase the time.

Start your script by running:

set_time_limit(120); // Script is allowed to execute for 2 minutes if necessary

Upvotes: 1

Related Questions