tags:

views:

36

answers:

2

if one web user is entering my php site and interacts with it then this php file will open one process (with one thread) and then after the php file is finnished with the logic and sent the output to the browser then the process is closed?

cause if it wasnt closed then it would mean that the values in the variables in that php file will be undeleted right? but since you always have to initialize new variables with values it means that the process is closed?

i just thought about this cause in a traditional desktop application i think the process doesn´t close unless you shut it down.

+2  A: 

It depends on the configuration. For example, if php is running as FastCGI, the process will not be closed and will keep running waiting for a new request.

Regardless of the configuration though you can be sure of one thing: all the variables/etc will be uninitialized when the script ends, so you (the programmer) don't have to worry about this. Regardless of the configuration and whether the process closes or not it will behave the same.

Andreas Bonini
+2  A: 

PHP is REQUEST driven. The interaction of a web server is as you described.

  • The REQUEST comes in to the server
  • Apache (example) creates a thread for the php executable
  • Your PHP script(s) are fired up, variables are init'd
  • Your script(s) complete execution, variables die
  • Apache cleans up
  • Your get a RESPONSE from the server

Yes, a desktop application and a php script running on a server are very different in those terms.

Mr-sk
ok so the process is closed after the last line in that php file is executed.
weng
No, not necessarily. Read my answer.
Andreas Bonini
But when the script completes, all the resources allocated by PHP (variables, file/database handles, network sockets etc) associated with the execution of the script are cleared down, however if it is running as mod_php in Apache, or as fastCGI, the PROCESS does does not terminate at this point - it merely goes into a standby state until it has a new request to service.C.
symcbean