Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>node.js is a non-blocking IO library capable of being used as a Web Server.</p> <p>Code Igniter is a PHP framework. </p> <p>Do you want to run a node.js Web Server beside your PHP Web Server and have them talk to each other? </p> <p>I'd recommend you do one or the other. Re write your entire website in <a href="http://expressjs.com/" rel="nofollow noreferrer">express</a> and <a href="http://nowjs.com/" rel="nofollow noreferrer">now</a>.</p> <p>If they must talk to each other you can easily open a TCP socket in node by using <code>net</code>.</p> <pre><code>var net = require('net'); var server = net.createServer(function (socket) { socket.write("Echo server\r\n"); socket.pipe(socket); }) server.listen(8124, "127.0.0.1"); </code></pre> <p>Then just use <a href="http://php.net/manual/en/function.fsockopen.php" rel="nofollow noreferrer"><code>fsockopen</code></a> in PHP to connect to node over a TCP socket.</p> <p><strong>Edit:</strong></p> <p>The live comments is completely independant of CI. You just need to have some socket.io javascript on you CI server pages. Your pages talk to node.js over a seperate socket and never touch the PHP back end. Your socket.io will push data to all your clients and the pages will render new messages with javascript.</p> <p>All codeigniter needs to do is insert </p> <pre><code>&lt;script src="url/socket-io.js" /&gt; &lt;script src="url/myChat.js" /&gt; </code></pre> <p><strong>Further Edit:</strong></p> <p>So you need your user to log in over your websocket. I'm not sure how they log in now but sending the same username/password hash to node.js shouldn't be too hard. Get node.js to open a connection to your database where you store users. Then store which channels / threads / chat rooms / messages a particular user is "subscriped" to in a database.</p> <p>Then when node receives a message from a "channel" it just asks the database which users to push that message to, and then it pushes it.</p> <p>I answered a similar <a href="https://stackoverflow.com/questions/5621642/node-js-creating-persistent-private-chat-rooms/5623761#5623761">question</a> about writing a chat server using node and the video tutorial of <a href="http://nowjs.com" rel="nofollow noreferrer">now</a> has a good example. You should be able to turn "multiple rooms chatting" into "multiple thread commenting" pretty easily.</p> <p><strong>Further Further Edit</strong></p> <p>Don't post to the URL <code>comment/add/</code> when you click add. Don't use ajax. Instead use socket.io.</p> <p>So something like:</p> <pre><code>// on the client side $("#add").click(function() { socket.send("add" + user.toJSON()); }); socket.on("message", function(m) { if (/^new/.test(m)) { var post = m.substring(3); $("#comments").append($("&lt;div&gt;&lt;/div&gt;").text(post)); } }); // on the server side var socket = io.listen(server); socket.on('connection', function(client){ // new client is here! client.on('message', function(m){ if (/^add/.test(m)) { client.broadcast("new"+m.substring(3)); } }); }); </code></pre> <p>So simply the client sends a "add comment" message when you click add. The server listens for the add message and broadcasts the message to all <em>other</em> clients. These clients are already listening for the new message, and new appends a comment.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload