0

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?

2
  • 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. Mar 19, 2013 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, 2013 at 1:56

2 Answers 2

9

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.

-1

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.

2
  • 2
    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. Mar 19, 2013 at 0:15
  • you can execute php through node the same way apache / nginx does. Mar 26, 2013 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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