1

I have a PHP system, that does everything a social media platform does, i.e. add comments, upload images, add objects, logins, sessions etc. Storing all interactions in a MySQL database. So i've got a pretty good infrastructure to build on.

The next stage of my project is to develop the system so that notifications are sent to the "Networks" of "Contacts", which are associated with one and other. Such as the notifications system like Facebook. i.e. Chris has just commented on object N.

I'm looking at implementing this system for a lot of users: 10,000+, so it has to be reliable. I've researched the Facebook integration, resulting in techniques such as memcache, sockets & hashing.

Are they're any systems that can be easily adapted to this functionality, as I could do with a quick, reliable implementation.

P.s one thought I had was just querying the database every 5 seconds for e.g. "Select everything that has happened in the last 5 seconds" using jQuery, Ajax & PHP, but thats stupid, it would exhaust the server & database right?

I've seen this website & this article, can anyone reflect on this to tell me what is the best approach as I am hesitant about which path to follow.

Thanks

cwiggo
  • 2,541
  • 9
  • 44
  • 87

1 Answers1

1

This is not possible with just pure vanilla PHP/MySQL. What you can do is set MySQL triggers (http://dev.mysql.com/doc/refman/5.0/en/triggers.html) on your data, and then use the UDF function sys_exec (Which you will need to install on your MySQL server) to run the notification php script. See this post: Invoking a PHP script from a MySQL trigger

If you can get this set up it should be pretty reliable and fast.

Community
  • 1
  • 1
DankMemes
  • 2,085
  • 2
  • 21
  • 30
  • Edit: the link on the post I linked to appears to be broken. Try this: https://github.com/mysqludf/lib_mysqludf_sys#readme – DankMemes Apr 10 '14 at 13:58
  • Would this be ok for a large amount of users? If this is so reliable/ fast why didn't facebook use it? Just thoughts that are running through my head. Thanks for the answer anyway, i'll have a go at implementation – cwiggo Apr 10 '14 at 14:18
  • There's probably the overhead of starting hundreds of notification processes all the time, because fb has millions of users. You only have 10k, so you are fine using this. – DankMemes Apr 10 '14 at 14:20