The background story
Is there a possibility to clearly state which one is better? Both technologies have their advantages and disadvantages and are to a far extent interchangeable. Was everything already said in the which is better debate, or can we come to any new conclusions? In this article, we’ll take a look at this clash of titans and compare Node.js and PHP to find out which solution may be more benefitting for an early stage startup.
PHP vs Node.js
- a good framework for real-time web apps (chats, games) due to the event loop and sufficient service of multiple concurrent requests
- has a wide range of hosting options and built-in server support
- efficient reusability of code due to a single syntax for client and server sides on the website
- great choice of open-source scripts, libraries and applications
- work with large files made easier due to stream modules
- lack of maturity (compared to PHP)
- difficulties in handling relational databases
Although Node.js is a younger technology and is still less commonly used than PHP, it is already used by big enterprises like eBay, Netflix and Yahoo, as well as a range of successful startups, including Trello. Thanks to the V8 engine and Just-in-Time compilation, it can transform JS into native code, boosting the development process, also, being a versatile solution is usable on a wide range of devices. Node is great for developing highly scalable and interactive server-side solutions. Example? As a real-time web development solution, Node makes developing chatbots or instant messenger easy.
Many startups choose Node over monolithic stacks (like PHP) mostly because of the ability to scale Node apps on multi-core systems, the significantly higher speed obtained due to the event callback mechanism and the possibility to use it as a multi-threaded application. It is worth to note that the increased popularization of frameworks that can apply logic not only on the server side contributed directly to a dynamic growth of single page applications.
What makes Node.js more popular is also a variety of ready-to-use packages written for the Node.js, thanks to which we can easily connect to almost any service or database. The most common Node integration dialect, however, is JSON, which speaks well with the NoSQL databases.
Last but not least, the community behind Node.js is large and getting bigger each day. The bigger the community gets, the easier it is to get support.
- mature (24 years on the market) but still actively developed
- there are many out-of-the-box solutions well known among the internet, like the prominent WordPress, world’s most popular platform among bloggers, CMS (content management systems) like Joomla, and CMF (content management framework) like Drupal
- is supported by most internet hosting services, especially shared hostings
- an interpreted language, meaning no compilation is required
- running nearly 80% of the internet
- wide choice of free frameworks, libraries, and packages
- requires extensions (CGI executable) for a web server to handle PHP code
- threaded execution
- stateless nature
- interpreted and not compiled language (combined with the stateless nature means that application needs to be built and ran each time there is a need to handle the request, and that means a lot of I/O’s)
PHP is a scripting language widely used for server-side web development, with a strong emphasis on compatibility with relational databases like MSSQL, MySQL, Oracle (thanks to PDO – built in SPL library to handle databases). We could say that PHP is great in the working with strings, filling arrays and reading files – all basic operation that every server-side application does while handling the incoming request. The speed of building PHP applications is related to lack of compilers, preprocessors or need to build JAR files. PHP code can be mixed directly with HTML (but we strongly do not recommend such way of doing web applications).
The language itself is accessible, available for free and independent from managing companies. Perceived as a better solution for medium-sized projects, especially content management applications or online shops. The PHP developers’ community is extensive and provides thorough guidance due to a long development era, making the search for solutions almost pain-free.
Let’s build an app!
Among various types of applications that can be built with Node.js we can list:
- SPA (Single Page Applications). The web applications or websites that interact with the user dynamically and require dynamic web server communication. Thanks to efficient handling of several asynchronous calls and I/O workloads, Node.js is the right solution for fulfilling numerous requests at once.
- IoT (Internet of Things). The wide range of traditionally non-internet-enabled physical devices and everyday objects, embedded with electronics and Internet connectivity. From smart doorbells to building automation IoT is a constantly growing part of the industry. Node.js enables processing of various concurrent requests in networks consisting of huge amounts of devices. Its event-driven architecture helps to process all the requests without blocking servers.
- Real-time chats. Most common real-time applications, used by many businesses to communicate instantly with their clients and partners. Chats transfer text, voice, video messages to one or numerous recipients. Node.js enables event-driven approach with a small data load and works well with the WebSockets protocol, creating faster real-time messengers.
- Streaming applications. Applications that require just the installation of some of their elements on the user’s device. All other elements are downloaded when needed, letting users run apps without the wait for large amounts of data to be on their device. Node.js contributes to these applications thanks to its abilities of efficient data streaming.
Types of applications that can be built with PHP include:
- Content management systems. Applications used for managing web content, allowing creation and publishing by multiple contributors. PHP’s code is relatively simple and contributes to easy site integrations.
- General web development, including enterprise applications development (applications built for organizations rather than individuals users, meaning usually large, complex projects.). PHP has a huge ecosystem, which brings to the table a range of frameworks and libraries, accelerating web-based enterprise apps development.
- Portable, self-managed apps. PHP is present on almost any shared hosting service. It is easy to install and manage. This allows even not very tech-savvy people to install applications in their environment easily, extend already owned a set of apps or just mingle with the technology and create quickly something on their own, without the hassle of spawning new server, configuring the whole environment or spawning new instances of the application.
And the winner is…?
At this moment, believing that Node.js is already established enough to replace PHP may be a bit of a stretch, but all the signs indicate that in the future it may become the ultimate solution for backend development. Current PHP 7.2 is a worthy opponent and won’t go down lightly, however, Stack Overflow tag trends show its slow decline. Node.js is faster (to develop and to work) and therefore it is more commonly used by startups, as the CodingVC report shows. The current trend for RTA (real-time applications), interacting with users in the immediate sense, might be the field where PHP loses to Node.js in the long term. Node has everything that an early startup needs, using the event-driven, object-oriented model that enables best performance in eg. e-commerce websites and other real-time mobile or web applications.
Taking all of the above into account, you may still not be sure what will be better for your projects. If the PHP and Node.js fight is too aligned, and the benchmarks do not give you a simple answer, think in the bigger picture. If the flexible simplicity of the MEAN (MongoDB, ExpressJS, AngularJS and Node.js) stack works for you, go with the newer solution. If you happen to find more adequate technologies in the LAMP (Linux, Apache, MySQL and PHP) stack, pick the more seasoned technology. After all, the choice needs to be done to select the adequate tool to solve certain problems and not based on a subjective opinion on the “best” technology. When in doubt what technology will be most suitable for your startup, consider joining the discovery workshops that will help you find the right stack.