1

Are there any languages or even servers that instead of running a script on page load, (Apache/PHP, Ruby on Rails, ...) actually keep the code loaded and running forever, and when it receives a connection it calls a function of that code? (Like a PageLoad event basically?)

I didn't really know how to call this so I went for Passive Web Server because the code is basically sleeping till an event occurs, instead of fully unloaded or just cached.

  • I am purely talking server side here, I think you misunderstood. When you connect to a PHP page, the PHP file gets parsed, optimized, run and cached. Are there any webservers that just launch a script and when a user connect to a page it sends an event to that script saying the user is accessing a page and it is expecting output. – Jeroen Sep 3 '13 at 20:18
  • I think this is how node.js works. nodejs.org – Reactgular Sep 3 '13 at 20:29
  • Anything that runs in a FastCGI context, apache modules or as an application server runs this way. See en.wikipedia.org/wiki/Application_server – user40980 Sep 3 '13 at 20:57
  • Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat Sep 4 '13 at 5:17
  • @gnat All I've done is Google'd "Event Driven Server" and "CGI Alternatives". None of these returned any relevant results. – Jeroen Sep 4 '13 at 14:23
3

PHP and scripts run through CGI (not FastCGI) are about the only things that work this way. Almost everything else has a long-lived process that runs & responds to requests. A typical web application will have a static server (Apache, Nginx...) in front, handling client requests directly. For static files (Javascript, CSS and so on), it'll just send the file; for things that require your app to respond, it will pass the request on to your application & then forward the response to the client.

One example would be a simple Python/Django install. We have Apache running on the server. As part of our Apache configuration, we're running mod_wsgi. The mod_wsgi module allows Apache to fire up a number of Python interpreters that have long-running jobs in them. When a request comes in, Apache sees that it should go to Python & hands the request over to mod_wsgi and mod_wsgi passes the request into your already loaded & running Django application.

Another example would be a Ruby on Rails application running behind Nginx and Mongrel. Mongrel is a web server that lets Ruby applications live inside of it. It's really good at serving dynamic pages but it's a little slow at static stuff, so we set up Nginx for that. Nginx serves the static content (like Apache did in the last example) but whenever a request for one of the dynamic pages comes in, Nginx just acts as a proxy and forwards the request to Mongrel.

There's a minor difference between the two cases but it's not really worth delving into unless you're handling server architecture for a high-volume website.

A third setup comes in with Node.js. With Node, the web server is your application.

| improve this answer | |
1

Node.js scripts typically work that way. They act as their own web server, essentially, but are a single process that stay loaded between client requests. This is why its so good at 'real time' communication - it can stack and manage multiple connections and pass data between them.

| improve this answer | |
0

Python through WSGI with Apache stays loaded. Frameworks like Django route the call to the appropriate module / class.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.