Answer the question
In order to leave comments, you need to log in
Which is faster PHP or Node.js?
It is assumed that we will have 1000 requests to the API of a third-party site, which should be sent by cron at regular intervals. If the request satisfies the condition, then we execute some code, otherwise we do nothing. A picture immediately arises in my head of how PHP will sequentially send one request, wait for a response, and only after that move on to the next one, while Node.js can send one request and move on to the next one without waiting for a response, and receive responses asynchronously. I have never worked with a node, tell me which of the culprits will cope with the task faster, and what are the pitfalls. For reference: the data for the job will be stored in MySQL.
Answer the question
In order to leave comments, you need to log in
A picture immediately arises in my head of how PHP will sequentially send one request, wait for a response, and only after that move on to the next one.discover curl_multi .
Everything will depend on the responses of the third-party API.
1. If the API is able to process asynchronous requests quickly (100ms) without queuing them, then node.js or just a page with asynchronous calls will process faster;
2. If the API needs to take serious actions to process the request (for example, 500 ms), then the savings will be negligible.
PS Synchronous calls are processed by the server with a higher priority and a priori get the result before asynchronous ones. And perhaps winning with asynchronous will not cover the difference. So if you have already written a script, then there is no point in rewriting it.
If you write a demon, you can take ReactPHP and enjoy life, everything is asynchronous, everything is on the event loop, in a word, the same node.js only on php.
In general, there are multi curl, stream_select and other joys of life.
The new php7, which will be released around November this year, will be fast like nodejs but will lose in terms of RAM costs, but who cares (and you will need to test it again)
Well, someone has not canceled using HHVM until php7 appears, I hope in the seventh version, just-in-time compilation will be added.
NodeJS - Inside the engine from Google V8. I think it's more optimized at a low level than earlier versions of PHP. benchmark . More real example . Perhaps the answer . But, I guess that GO will be even faster :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question