Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My server has a limited number of concurrent processes (20) it can handle. To make sure I don't exceed I need to understand:

  1. When a user is waiting for a PHP script to finish loading, does the entire waiting duration count as one process?

  2. Most of the time waiting for the script to finish is communicating with a remote server via cURL... I believe most of the time is simply waiting for the server to respond with data. Does the whole time connected to the remote server count as a process?

I do payment processing and need to make sure nobody gets cut off. Script are run thru mod_fcgid.

share|improve this question
up vote 0 down vote accepted

This all depends.

If your server is running Apache with mod_php, then your PHP script will be run along with the Apache process and counted as one process (the one Apache is running for that HTTP request). However, if your script uses system calls for using external programs, then it naturally will spawn new processes and run them. Worth noting is that under mod_php each script is run with the user id Apache is running, so if the server has many users, each of them are using the same resources than the other.

If your web server is configured in some other way than Apache + mod_php (such as Apache + suPHP or Apache + fastCGI or Apache + mpm engine), counting the processes is a completely different beast. Then the scripts are run as the owner of the script and separating the resources is more simple. The principles are the same, though: each script is a single process unless it calls some external programs.

share|improve this answer
My server uses mod_fcgid (fastCGI). What does it mean for the server to use "system calls for using external programs"? My script contacts a database, writes to session, and connects via cURL to a remote server (the main things). I understand that these all count as processes, but does the entire PHP script itself count as a process? – Hope4You Mar 12 '12 at 18:57
System calls means using something like system() or exec() within PHP, which spawns some external system binary from /usr/bin/, /usr/local/bin or so. – Janne Pikkarainen Mar 12 '12 at 19:02
So the script itself counts as a process. I do not use system calls. Do the things the script does (contacts a database, writes to session, and connects via cURL to a remote server) count as separate processes? Or will the number of processes always be 1? – Hope4You Mar 12 '12 at 19:05
Everything that's using standard PHP functions is using the same process. At least database and session is going to be a single process, with curl are you using PHP's curl functions or calling curl with some external system command? – Janne Pikkarainen Mar 12 '12 at 19:08
PHP's cURL functions. – Hope4You Mar 12 '12 at 19:09

Yes, normally from the time you start a script until the time it ends you have at least one process running. But the script can spawn more processes or threads.

However, though I didn't look into this, I would say that if you start a script from a webserver because of a user request the script could, for example, be spawned as a thread from the webserver's process, or run as part of the webserver's process. So to give precise information one would need to know what exactly you are running.

Update: From your comment it seems it may be helpful to look into a solution where you have one process running, which then spawns threads for each request. This can improve speed a lot, but it comes at a cost (for example threads only run as long as the parent runs).

Also you might want to look into queuing the connections. In simple terms, your script can handle multiple connections and goes through each handler checking if the remote server already responded, if not it goes to the next etc. This is quite typical in handling tcp connections and you only require one process and don't need threads.

Anyways, discussion of actual programmatic solutions falls outside the scope of server administration and enters the realm of programming.

share|improve this answer
Okay, thank you. My script takes 7 seconds. My server only allows 20 concurrent processes. So if the script itself uses a process, as well as the other processes it performs, it sounds like it may not work in high traffic. If the script itself did not count as a process, that would help. Do you know if waiting for a remote server to respond with data (via cURL) counts as a process? – Hope4You Mar 12 '12 at 18:50
Yes, IF the script is started as a separate process and as part of it's duty it is waiting for a remote server than that is still a process. However waiting for a remote server to answer does take almost no resources. The process is put to sleep and is woken up once the remote server answers, or the transaction times out. – aseq Mar 12 '12 at 20:44
See updated answer. – aseq Mar 12 '12 at 20:53

Your Answer


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.