1

What I do know, is that NodeJS's reponses to requests are faster than PHP scripts, because NodeJS server is always running, in a loop waiting for events (this is how I understand this).

But I'm wondering what exactly happens when we make a request to a PHP script. Is the entire PHP engine loaded into memory every time? Or maybe something else must happen?

I'm asking this because I recently had a discussion with a friend of mine. I wrote a "comments" module to an existing application. When comments are displayed, I shorten longer comments and I add a link like "show more" - this link only makes a given comment visible, nothing more, because the full content of the comment is already there. And he said that in his opinion it's better to download only a part of a long comment at the beginning, and then when user clicks "show more" I should use AJAX to download full content of the comment and then display it. I always thought that every, even small request, is very CPU and memory greedy. Hence the question.

konrados
  • 1,047
  • 8
  • 21
  • 1
    The CGI execution model is just PHPs default. Nowadays it's running as FPM/FastCGI daemon, just accepting incoming requests. Though you could write a custom "application server" only processing individual requests from a long-lived script. – mario Jul 11 '15 at 13:15
  • Thanks. I entered "CGI execution model" in Google, and I couldn't find anything, but, since as you say it's running as a daemon, it should be as fast as NodeJS in terms of responding to requests, am I right? So why is it slower? – konrados Jul 11 '15 at 13:23
  • 1
    See http://www.reddit.com/r/PHP/comments/2oviye/what_is_the_php_execution_model/ or [I never really understood: what is CGI?](http://stackoverflow.com/q/2089271). Performance depends on the concrete implementation, or need for vertical scaling (what multiple processes are often better at than appserver-style runtimes). – mario Jul 11 '15 at 13:28
  • Thank you! Somehow I couldn't find it:) – konrados Jul 11 '15 at 14:54
  • @mario - just one more question:) - I found, that I can use the php-sapi-name function to get the type of interface. On one server it returns cgi-fcgi - OK, I understand that this is FastCGI - I've just read a bit about it. But on the other server it returns apache2handler - what does it mean? Is this an Apache module (mod_php)? – konrados Jul 11 '15 at 21:52

0 Answers0