PHP vs. Node REST-API

I am creating a simple REST API that has one endpoint that will be badly broken. Let me call it POST /message . I have to decide between using Node or PHP. The database is MySQL.

What happens inside this route: - Credentials through HTTP-Auth will be verified by reading them from the database. - Request for another REST-API. - Another action will be taken with the database record.

Thus, there are two database connections and an HTTP request to another REST API. The route should be about speed. I would go for PHP because the current system is based on PHP, but the query inside the route scares me because it does not do asynchronously when using PHP. I donโ€™t care about the result of this query, and in Node I can just check the credentials and return success , send the request asynchronously and write a database record after the request returns. I donโ€™t think I can do this in PHP, because when I return a REST call with success , everything should be done earlier, right?

Go for php or node?

+5
source share
1 answer

You wrote:

makes it do asynchronously when using PHP

Are you sure this is not possible? Not Even With Aszz Gambling Requests ?

In any case, I implemented the same REST API server in several languages โ€‹โ€‹and tested it on the same computer (Ubuntu Linux 16.04, Intel NUC i7, 16 GB RAM) and found:

(a source)

Please note that Node.js was the only platform that could not efficiently use multiple cores.

To simulate your requirements, I tried adding 15 ms to the first PHP and 15ms setTimeout to Node.js, and found that when you hit with 2000 simultaneous requests, Node.js was higher (4300 versus 1800 req / sec), but also higher latency (450 vs 130 ms / repeat). Probably because he used only one core and had to respond to many events. This higher latency with higher throughput can be caused by the use of an event loop. Using the Apache (pre) fork can be more expensive, but able to achieve higher concurrency.

Iโ€™m not sure that all this will help you a lot directly, but it can give you a starting point for your own research. Enjoy!

+8
source

Source: https://habr.com/ru/post/1263158/


All Articles