Php Chinese network (www.php.cn) provides the most comprehensive basic tutorial on programming technology, introducing HTML, CSS, Javascript, Python, Java, Ruby, C, PHP, basic knowledge of MySQL and other programming languages. At the same time, this site also provides a large number of online instances, through which you can better learn programming... Reply content: no problem description or methods you have tried. you can only assume that your scenario is "how node reads php sessions". This should be the most common situation.
PHP exposes a Service and provides Session data to Node.
Php_session.php? SID = xxxx
Nodevar request = require ('request'); request ('http: // localhost/php_session.php? SID = xxxx', function (err, res, body) {if (! Err & res. statusCode = 200) {// use body (json) as needed )}});
You can use third-party caching tools, such as memcached.
Refer to this article: PHP and Node. JS session share using memcache
Use a third-party storage such as redis to save the session. It is better to put the session on the server side.
You can use the cookie to set the cookie survival time expire to 0, which means that the cookie fails when it is disabled by the browser. The survival effect is similar to that of the session, which makes front-end operations much easier.
Is note. js running on the server? When running in parallel with php, you can consider sharing sessions with third parties, memcache, redis, and databases. We recommend that you use redis or memcached for the session, so that not only the node and php programs can share the session, but it does not cause additional overhead for php and node programs.
If the session is stored in the memory of node or php programs, additional code and resource maintenance are required. Second, the code is not as mature as the solution for redis and other k-v databases, on the contrary (if the code is unreasonable), it is likely to cause bugs or performance bottlenecks. For example, the method for exposing php service mentioned above, or exposing node service, does not require human overhead to write or maintain code, and the online request processing capability per second is generally php <~ Node <
As for php, I have never understood it. to support multi-host and horizontal scaling, redis-like solutions still need
The disadvantage of this solution is that it can only store general data and cannot store object references. to put it bluntly, what is sharing? It means that the same piece of data can be read by PHP and by Node. js.
As for how to read it, you have to read it yourself. you can store the database, Memcache, or even directly leave the interface to Node. js through PHP (just like the method provided by flamingtop ). The purpose of session is to store data in the server's memory. if you know this, find a memory database (redis, memcached ...) you can achieve your goal. if you think these are too heavyweight, just write a lightweight memory database in a language you are familiar, cross-language interface or inter-process communication is recommended. sock file. We recommend that you use redis and php to directly configure the session scheme. nodejs also has many lib general practices that use the session server. it is feasible to use mature solutions such as mysql or memcache.