N
N
nepster-web2014-03-13 20:05:04
PHP
nepster-web, 2014-03-13 20:05:04

Communication between php and node.js, how to optimize or maybe remake?

I've posted a similar question before, but I can't seem to come up with an optimal solution.
Actually the situation:
There is a game Deberts on node.js, well, the site itself is on php (Yii).
Everything works as follows:
The user creates an application and waits for rivals. It's all within the site. For real time I use:
https://github.com/Yaffle/EventSource/
Here I noticed 2 points:
- this library does not work in opera mini.
- for some reason it’s not clear how it didn’t work for a friend on a PC at all in any browser (win7, all browsers of the latest versions).
When a user creates or joins a ticket, he receives the appropriate cookie (game hash : user ID hash). Further, when all opponents have connected to the application, the creator of the application presses the play button. It is redirected to the verification page, where I do all the necessary checks for the number of participants, whether they can play, etc., I enter the relevant data into the database and, using the
elephant.io library , send data about such and such a game to the port I need .js
Then the creator of the application flies to the game at site:ru/play/deberc/, and all the rest fly after him due to realtime. (At the time of all checks, I change the status of the application from pending to playing), and the pending js gets status 1 and redirects (locahion.href).
Now node.js issues cards to opponents based on cookies. Cookies are different every time, so it is hardly possible to fake them during the course (from 30 seconds to 2 minutes). When users have played the game, node.js makes a GET request to php, passing it data about the end of the game (who won, who lost, etc.). PHP does all the necessary manipulations, writes to the database and changes the status of the game to closed.
This means why the decision was made with cookies, the situation when the user opens the 2nd window or accidentally closes the browser and opens it in a new way, then he can get back into his game.
So, what problems and questions arose:
- I heard something about a radish pub / sub, but I didn’t understand what it is, I didn’t find a good article in Russian, or I didn’t fully understand what it is and why it works and how it works. I only realized that a radish is something like a database, or maybe a storage like a mmcache.
In general, is it possible to implement real time and interaction with node.js using this technology?
- another moment, if node.js crashes and an error occurs somewhere, or simply for some reason it did not transfer data to php, then php does not change the status of the game, which means that all the players of the current application are stuck on the site.ru/play/deberc page, since I am redirecting all the pages of the site to the game. What can be done here?
- I configured php.ini so that if the user is inactive for more than 30 minutes, then we break the session. And here the situation is, if the game goes on for more than 30 minutes, then the user loses the session and, in general, it turns out nonsense.
Can you please tell me where I need to dig in order to work out well my situation with php and node.js communication?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan, 2014-03-13
@nepster-web

I only realized that a radish is something like a database, or maybe a storage like a mmcache.
In general, is it possible to implement real time and interaction with node.js using this technology?

If you know what memcash is, then it is almost the same as a radish. For your example, I can hardly imagine where it is applicable.
You can fake cookies in 1 second. If not with your hands, then for example, let a bot into your game
.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question