Welcome! Log In Create A New Profile

Advanced

Re: Variable value is resetting

Maxim Dounin
November 10, 2021 03:02PM
Hello!

On Wed, Nov 10, 2021 at 01:12:22PM -0500, malzad wrote:

> I have a static int variable in a load balancing module and initially set it
> to 0. I want to update this variable when there will be any HTTP requests
> with certain criteria. It gets updated but whenever the module receives a
> new HTTP request ( or after receiving a few HTTP requests), that int
> variable again resets to 0. how can I prevent it from resetting the value?

Static variables in C are initialized to 0 on process creation,
and that's all, there is nothing that can reset the variable to 0
except your own code.

Note though that there can be multiple worker processes in nginx,
and if you see the variable being 0 after you've updated it in a
previous request, likely this means that you are looking at the
variable in the different worker processes. To fix this, you have
to re-think your code with multiple worker processes in mind.
Depending on what you are trying to do, using a shared memory or
writing logs might be a way to go.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Variable value is resetting

malzad November 10, 2021 01:12PM

Re: Variable value is resetting

Maxim Dounin November 10, 2021 03:02PM

Re: Variable value is resetting

malzad November 10, 2021 08:02PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 150
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready