简体   繁体   中英

Web application using Node.js/socket.io and php/mysql

I am relatively new to node.js and socket.io. Currently I have a half finished private web project, which runs only with PHP with a MySQL database on the server side. I decided to bring it to a more advanced level using socket.io, for several features within the project.

So I read a lot about it and watched a whole bunch of tutorials. Also I found this and this during my research.

My question is, if that is still the common way to develop a web application?

More exactly: to use on one event (like a form submit) both an AJAX request and a socket.emit, for those events it is necessary/wanted.

The background of this thought is the following. I have a whole bunch of calculations running now in PHP. And the node.js server runs logically in JavaScript. So I can easily implement a node.js server without changing anything on my AJAX requests. Or rewrite everything I have so far, to js and use only a node.js server.

But this leads to 3 more questions:

  1. Which runs possibly faster on the server side. A calculation scripted with PHP or JavaScript?
  2. How to use transactions on a node.js server while using MySQL?
  3. And how great is the influence by converting a PHP array to a JSON object, what you could avoid with the usage of just the node.js server where you don't need to convert anything.
  1. JavaScript is executed on the client side so you are limited by the user's hardware whereas PHP is executed on your server. See this post for more info about performance comparaison.
  2. I highly suggest you take a look at this pure node.js client that will perfectly do the job in your case.
  3. PHP has many functions to use on JSON data ( json_decode(), json_encode(), ... ) but Node.js don't require JSON data to be converted. In the end, it really depend on your usage and how you plan to store and use that data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM