Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am creating an application with a friend, which we are planning on writing the back end partially in PHP and partially in Javascript with Node.js. Javascripts front-end involvement with PHP makes this a tough question to Google.

We are also using ejs templates, MySql database and it will be run on a Fedora server if those factors matter.

Question: I would like a basic understanding of how they combine and maybe more importantly if it is better to prepare for this merge now or if it is something we can figure out later?

share|improve this question
2  
Please add the "why" to your question. What is the reason you would want to do this. Otherwise a good answer is not possible. –  Luc Franken Mar 19 '13 at 10:40
    
The why is because I do not know PHP and have already started the code with nodejs and I have set a particular deadline that I would like to meet based on the demand in a seasonal market so I need to bring in help to meet this deadline –  Steven Mar 20 '13 at 1:56

2 Answers 2

up vote 8 down vote accepted

Why on earth would you ever do that?! I can understand using different languages for tools, server and client side components, but mixing high level, interpreted code for a single component?

Never mind the overhead of just getting PHP and JS to talk to each other on a machine (I'm assuming you'd have to resort to sockets), but you're incurring overhead for developers by forcing context switching across two very different paradigms whenever they want to jump from one portion of server code to another.

Now don't get me wrong.. Node.js has its benefits as does PHP (well, I don't advocate the use of PHP for anything in this day and age, but that's just me). But, unless you're developing a highly complex distributed system with multiple reusable components developed by teams, I can't see the benefit of using two languages to solve one problem in any way, shape or form.

On the other hand, at least you wouldn't have to do any context switching (or minimal at least) if you're jumping from server to client using Node.

Edit:

So, as an actual answer to your question: Yes, they can absolutely be combined together. However, I would not recommend it unless you're building a complex, distributed application with multiple teams which have hired people who are very strong in a given language or technology.

share|improve this answer

You can do this, but it may be a little cumbersome. My understanding is that node.js would run as a http server so unless you plan on running php in nodejs! you will need 2 webservers running on your server, one on port 80 and the other on another port. This will work fine, but any request to the other will need the port at the end of the domain name http://example.com:8800. Unless you run them on seperate servers.

I would however ask yourself if you really want to do this or if its just to see if it is possible. What are you doing in Node that you cant do in php and what are you doing in php that you can't do in node.

share|improve this answer
1  
node can run a pure tcp server just as easily as a web server. for all we know, the OP was interested in using a services architecture where the PHP portion simply communicated with a service backend written in node. in that case, you wouldn't need two web servers. also, unless i'm mistaken, i'm not aware of a node-based php interpreter. –  Demian Brecht Mar 19 '13 at 0:15
    
you can execute php through node the same way apache / nginx does. –  Jan-Stefan Janetzky Mar 26 '13 at 8:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.