PHP and JavaScript – Can PHP and JavaScript Do Backend Together?

javascriptPHPweb-development

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?

Best Answer

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.