Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Suppose we have a typical LAMP setup. When a person requests a web page coded in php, what happens at the Apache level? Does Apache create a new php instance to create and return that web page? Or is there a continuous php instance running at all times?

Basically, here is how I think it works:

  • Person visits http://example.com/index.php

  • Apache receives the request, spins up an instance of php to create the page

  • Page is created, sent back to the requesting browser

  • PHP instance is closed

Thus, only one php instance deals with page requests...Is my thinking correct on this?

share|improve this question
    
Depends. mpm-prefork uses "workers" that execute the PHP and pass the result back, while mpm-worker uses Apache's internal workers and mod_php to execute. –  Nathan C Oct 1 '13 at 14:18

1 Answer 1

up vote 2 down vote accepted

It depends on how you are utilizing PHP. If you're not utilizing CGI/FastCGI (which would make your statement correct) then PHP is actually run in a module (see /etc/httpd/conf.d/php.conf, or httpd.conf for the include php module). Which means that when Apache has a kid, each process already has a binary of PHP. So, Apache runs the interpreter against a set of hooks and the page is rendered.

CGI is the method which is executed as a single process.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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