简体   繁体   中英

PHP session to be shared with Node.js using FileSystem?

There are several methods to share PHP session with Node.js.

One method is saving the PHP session in a nonSQL Database such as Redis and access it through Node.js.
Another popular method is using a memcached server.

Both of the mentioned methods require:
1) Running another server.
2) Altering the default PHP Session handler.

Why shouldn't I use the default PHP Session handler and access the sessions files by reading the file content within Node.js using 'fs'(FileSystem) core library ?
What other reasons there are besides speed to not access and read the sessions files directly, assuming that no remote operations between servers should be done ?

One huge advantage to both of the external session server options is that it becomes much easier to server the PHP and Node apps from separate servers themselves. While it's possible to access another server's filesystem directly, as would be necessary using the Node fs library, it's much simpler and more scalable to externalize the sessions on a redis server, for example, and not have to worry about the filesystem at all.

I also recommend reading The Twelve Factor App for more good practices in this vein.

This answer is very comprehensive: Performance of Redis vs Disk in caching application

Apart from that consider that you could deploy your application and DB on remote servers, if you are using Redis or so. Especially if you are considering to containerize your application this will be an advantage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM