Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS+MySQL instead of PHP+MySQL. Is it ok?

I've read about NodeJS but couldn't find its dis/advantages. Can i replace a PHP/MySQL application with NodeJS/MySQL? is it good idea?

Please consider a PHP CMS. Can NodeJS do as well as PHP? Is NodeJS only suitable for some lightweight actions?

If it is ok, which MySQL module is the best one?

like image 805
AHHP Avatar asked Sep 24 '11 10:09

AHHP


People also ask

Is it okay to use MySQL with node js?

Once you have MySQL up and running on your computer, you can access it by using Node. js. To access a MySQL database with Node. js, you need a MySQL driver.

Can I use Nodejs instead of PHP?

If speed is extremely important for your application, e.g. a browser-based multiplayer game or a chat application, Node. js can become a better choice than PHP. Comparing Node. js with PHP, the first is inherently asynchronous, event-driven, and non-blocking, while the second is a synchronous programming language.

Should I switch from PHP to node js?

TL;DR: usually, PHP works better when it comes to standardized systems based on forms and databases, while Node. js should be your choice if you're thinking of highly interactive, modern apps working in real time. This is why many developers (PHP devs among them) are seriously considering moving to Node.

Is Nodejs safer than PHP?

Node. js is fast and lightweight. It is more secure than PHP.


1 Answers

Before getting into Node.js hype, read the following article.

Basically, Node.js HAS issues. It's a server, but you can connect to MySQL via Node and send data to the user. There are many pitfalls, one of them being that you must know JS and you'll have to format your output via JS instead of PHP.

However, your bottleneck will almost never be PHP, unless you do some stuff that PHP wasn't designed for (like loading 1 million entries in an array and doing various searches using that array and what not). What you'll find to be your bottleneck (in case of a busy website) is the HTTP server since you'll probably exceed memory due to each connection requiring certain amount of memory and of course - your DB will be (most likely) I/O bound (hdd bound).

In this whole process, PHP will be the least of your worries. Using programs written in C or for Node won't help speed things up, as you'll have to scale your database system - which is a whole different story (plus you'll need to scale your HTTP server setup).

Basically - stick with PHP/MySQL, forget about Node, at least for now.

Update: since this answer is accepted and technology caught up, it's good to warn new people: Node.js became popular beyond anyone's wildest dreams and I personally find it awesome. I'm lucky enough to be able to use both node and php interchangeably.

Node has great community and awesome packages, package managers and task runners. Anyone familiar with JS is able to work with node instantly. It's great, extremely useful and I see node as something that will propel JavaScript to do what Java was originally designed for (this is opinion based on anecdotal evidence and not a fact).

Bottom line: when choosing a technology, one should choose the one that they're familiar or expressive with. Both PHP and Node.js are great in its own way, there is no definitive way of determining which one is "better".

like image 119
N.B. Avatar answered Sep 28 '22 09:09

N.B.