views:

22

answers:

1

I'd like to implement a badge/reputation system on one of my site. When a user performs an action an event will be raised (ex: QUESTION_PUBLISHED) so that the system can check if a new badge can be awarded to the user.

The logic for some of the badges is quite complex and would require slow sql queries. Instead of using cron jobs I was thinking of using asynchronous calls. So basically I would have:

  1. User performs an action (ex: post a comment)
  2. Event is raised (ex: COMMENT_POSTED)
  3. Badge checks are done asynchronously (CheckJournalistBadge())

Is #3 feasible in PHP?

+1  A: 

I don't think asynchronous calls are possible in PHP, but you could sort of simulate. Maybe put the requests in a database and have a cron job that only checks for those requests and marks them as checked or even deletes the rows checked while adding the result (for example if badge is awarded) to the user table (whichever that would be in your case).

Claudiu