Can I integrate Nodejs with Cakephp?

I want to track in real time the data that users enter in the comments table. I have an Apache server, and suppose it has a node server on port 1337.

How will I do this every time someone saves new data, for example, return me the total number of table rows in comment and show it in view ?

Maybe you need to do $this->Comment->save($this->request->data); using another port using httpsectect ?

+7
cakephp
source share
2 answers

Yes it is possible.

You have several ways to resolve this issue, let me give you my ideas

You can simply use a lengthy survey and not use Node.js. at all. This is the right solution if there is not too much traffic, otherwise you will have a bad time.

You can use websockets and not use Node.js at all. Here you will find a basic guide to websites and PHP . Although, I’m almost sure that you can’t create “rooms”, that is, send notifications for specific comments.

You can also use Ratchet . It is a more sophisticated library for processing web maps and supports rooms.

Finally, if you want to completely immerse yourself in Node.js and CakePHP, I would suggest starting by watching this talk on Cakefest 2012 , which accurately describes your scenario.

After that, you can learn a little about Socket.io . This is a more complex solution, but it is what I used when integrating CakePHP and Node.js to create real-time applications.

The strategy here is for users to join the room , when they visit / article / view / 123, let's say the name of the room is articleID, then socket.io will listen to the events happening in this room.

You will have a Cakephp method that handles the persistence. Then, when the user submits the form, which you do not directly invoke the Cake action, you have socket.io to send the event, and then in your case you send the data to the server (Node.js), and nodejs will call your cakephp, which stores the data . When Nodejs receives confirmation from CakePHP, you send an event (using socket.io), this event will let all users connected to this room know that a comment has been made.

+9
source share

You have a choice between Websockets and long polling.

Decide which technology you want to use, and start implementing your use case. Keep in mind that websites are more or less new. Depending on your requirements, you won’t be able to use Websockets because you may have to support crappy browsers. See this page .

+1
source share

All Articles