Brian Kim wrote:
Hi. All.
In mod_proxy_http.c, I globally declared a variable, like unsiged int count = 0;
And I make it increase whenever the proxy gets a new http request.
I expect it increases like 1, 2, 3, 4,... but it is always same 1.
Does anydoby know why this happens? How can I use a global variable in
mod_proxy_http?
Not a simple answer, but read this :
http://marc.info/?l=apache-httpd-users&m=124467015611975&w=2
The basic point is : when it starts, Apache is a single process. That
one loads mod_proxy, with your variable initialised to 0.
Then that main Apache forks into children. Each child is an exact copy,
thus also with the variable = 0.
The main Apache does not serve requests, so its copy always remains 0.
But it distributes requests, 1 per child, as they come in.
So probably your first request gets handled by child #1. It serves the
request, and increments the variable, which for this child is now 1.
Then your next request comes in, and is handled by child #2.
Its variable is still 0. So it serves the request and increments the
variable.
Then your next request comes in and is served by child #3.
And so on.
Until... enough requests have come in, that a child that has been used
before, gets re-used. Then the variable is at 1, and now becomes 2.
But only in that child.
And so on.
Got it ?
If you start your Apache with a maximum of 3 children e.g., then after 4
requests you are guaranteed to see a 2.
Morality : you have to find a place to store your counter, that is
common to all children (or threads). And of course synchronise access
to it.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
" from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org