Every afternoon at 2PM our students participate in something called Tech Watch.
This consists of a 5 minute presentation done by each individual student on a hot topic that is currently trending in the tech world. As the tech sector grows and the variation of topics expands, we want to share our students opinions on these topics.
This week we begin with Rayan, she writes about the advantages and disadvantages of using PHP and Node.js. She begins by comparing them technically and ends with her own opinions on the differences between the two.
In our current project at Codi we are using Node.js even though we have WordPress which we can also use. Does anyone know why we use Node.js instead?
Introduction & Definition:
PHP and Node.js are both powerful back-ends for dynamic websites. They both fall under the same category, yet their features are quite distinct.
Node.js and PHP are both server-side scripting languages. One is not better than the other, the project needs should determine which one would be more preferable to use.
1-Both PHP and Node.js are interpreted languages.
2-Both are used to build websites and both are run on server-side (different reasons make one more preferable over the other).
2-Complexity of use: PHP is much simpler to use compared to Node.js, Node.js is not complex to use but requires more lines of code and a basic understanding of closures and callback functions.
3- PHP uses a multi-threaded blocking I/O to carry out multiple tasks to run in parallel with each other but Node.js uses an event-driven non-blocking I/O execution model.
4-Execution: PHP is synchronous and Node.js is asynchronous.
5-Execution Speed: PHP is slower than Node.js.
6-Web Server: PHP runs on the Apache web server and Node.js uses the NPM package, this package does not require a web server.
7-Package Manager: Composer package manager is widely used in PHP and Node.js uses NPM.
Different reasons can make one more preferable than the other, Node.js is more extensive and faster compared to PHP which may make it a more viable choice.
However, some programmers prefer PHP because it is easier to pick up than Node.js and it features an integrated database.
---> using PHP or Node.js depends completely on the nature of your project<---
When to use PHP?
1-Centralized Server: In case we do not plan on scaling our application across multiple servers we can use LAMP.
2-Portability: The cheap costs of web hosting and the availability of the servers for PHP is second to none, PHP can run on almost any platform that has Apache, IIS and has a supported database system installed.
This makes PHP applications portable and easy to deploy.
The CMS, such as WordPress, Drupal or Joomla, makes it easier to create websites and work on almost every web host. WordPress powers 30% of the web.
When to use Node.js?
3-Speed: Node.js is faster than PHP when it comes to execution speed. Speed is what you require for your application, such as a browser based multiplayer game or a chat application. For speed, Node.js is a better choice than PHP.