dev.pus
dev.pus

Reputation: 8139

PHP and Node.js or only Node.js?

I want to write a simple chat application (for test use).

The users and messages are getting persisted in MongoDB, the session are getting stored with Redis.

The PHP (Symfony2) is providing authentication, registration, passwort reset, etc. and serves the public site (like /, /contact, etc.).

When the user has logged it has controll to the chat application. Backbone.js handles the application and node.js provides the data through rest (or socket.io).

Should I use either PHP and Node sidebyside or should I only use node?

The pro of only using node would be that there are no port collisions the contra is that the node app gets quite big and not so readable (IMHO: cmf, registration, authorisation, email handling would be easier to do with symfony than node)

Upvotes: 3

Views: 1261

Answers (2)

mako-taco
mako-taco

Reputation: 732

You can try using JooDee, a node webserver which allows you to embed serverside javascript in your web pages. If you are familiar with Node and PHP/ASP, it is a breeze to create pages. Here's a sample of what a page looks like below:

<!DOCTYPE html>
<html>
<:  //server side code in here
    var os = require('os');
    var hostname = os.hostname();
:>
<body>
    <div>Your hostname is <::hostname:></div>
</body>
</html>

Using JooDee also lets you expose server javascript vars to the client with no effort by attaching attributes to the 'Client' object server side, and accessing the generated 'Client' object in your client side javascript.

https://github.com/BigIroh/JooDee

Upvotes: 1

igorw
igorw

Reputation: 28249

It totally makes sense to keep your web application logic in PHP. That's what PHP is good at, and porting it to node.js code would probably be a wasteful and painful experience.

Node on the other hand is good at networking and serving long-running connections, such as WebSockets (socket.io, SockJS, etc.). So having a chat server using that also makes sense.

I suggest you use both, since each one of them solves a specific problem that it's good at. You can easily connect them using some kind of message queue.

Upvotes: 4

Related Questions