we have our old website built on LAMP stack with user authentication. Now we have built a new social platform for the same users with live chat features, video and discussion forums etc and we have used node.js for this purpose.
When a user is logged in his account in the old site - lets say he can click on a link
www.xyz.com/social
which will take him to this new node.js platform.
So I'm not sure on how to pass user details from apache to node.js - All I will need is user id and then in node.js - I can query the mysql table and load the user details.
Simple Solution
The simple solution is to hash the user id and email and store the hash as key in memcache server and pass user details as values
$hash = md5($user_id+$email); $memcache = new Memcache; $memcache->connect("localhost",11211) or die ("could not connect"); $data = json_encode(array("id"=>$user_id,"name"=>"aaa")); $memcache->set("key-".$hash,$data);
And then in the link pass the hash value as parameter like
www.xyz.com/social/$$hash-value$$
and in node js - retrieve the user details from memcache based on the hash key.
1) Is this the right away to approach this.
2) Will memcache support storing data of so many users (around 500 users at a given time) moving within the website from the old site to the new node.js site.
Thanks in advance for your inputs.
If you're prepared to re-write your PHP in JavaScript, then yes, Node. js can replace your Apache. If you place an Apache or NGINX instance running in reverse-proxy mode between your servers and your clients, you could handle some requests in JavaScript on Node.
1) Is this the right away to approach this.
Yes, it is right to do like this. But there can be better approache to this issue:
Choose invalidation conditions properly.
2) Will memcache support storing data of so many users
Yes, it will.
But it largly depends on your memcache deployment, how much RAM are you providing to it ?
Calculate or get a rough esteemate that how much RAM is needed to store 500 user details. Once memcache went into swap, then serving these much requests would be pain for memcache.
But, as per me, better method for you would be sticking to MySQL only.
md5(user-id . timestamp. KEY)
, and save this entry in database.Reasons
Memcache is meant to be a data caching service, not a data transfer service. There's no guarantee that a value stored in the cache will be available to the other component.
What you are trying to do will mostly work, but will likely have weird issues when you start putting some load on the system. You probably want to use a message queuing system like RabbitMQ or Kafka, or back memcached with a database.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With