# How can I keep a large list in apache memory

**URL:** <https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836>\
**Category:** NGINX\
**Created:** [March 9, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836 "2010-03-09T12:12:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramprasad\_ap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@ramprasad\_ap](https://www.ruby-forum.com/u/ramprasad_ap)\
**Post date:** [March 9, 2010, 12:12pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836/1 "2010-03-09T12:12:51Z")

</div>

Hello all,

I am new to nginx , I am using ngnix as a Load balancer for two imap  
servers. All machines are RHEL5 64 bit

The nginx calls an apache php script that determines if the user is on  
imap1 or imap2 by looking up a plain text file.  
which contains entries like

## $user[‘user1’] = 10.1.1.1; $user[‘user2’] = 10.1.1.2;

$user=10.1.1.1;

For 15k users this method becomes very heavy. There are too many httpd  
processes running that suck the resources on the machine.

Is there a way I can load the userlist into memory in apache  
Thanks  
Ram

Posted at Nginx Forum:

> **[How can I keep a large list in apache memory](https://forum.nginx.org/read.php?2,61798,61798#msg-61798)**
>
> Hello all, I am new to nginx , I am using ngnix as a Load balancer for two imap servers. All machines are RHEL5 64 bit The nginx calls an apache php script that determines if the user is on imap1 or imap2 by looking up a plain text file. which...

---

<div class="post-metadata">

**Author:** ![ramprasad\_ap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@ramprasad\_ap](https://www.ruby-forum.com/u/ramprasad_ap)\
**Post date:** [March 9, 2010, 12:39pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836/2 "2010-03-09T12:39:12Z")

</div>

Why not store the key/value pairs in memcache? This works like charm and  
using  
Nginx’ memc and eval modules you can retrieve the IP addresses from the  
cache  
instantly.

On Tuesday 09 March 2010 12:12:06 ramprasad\_ap wrote:

> $user[‘user2’] = 10.1.1.2;  
> Is there a way I can load the userlist into memory in apache  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

Markus J. - Technisch Architect - Buyways BV  
[http://www.linkedin.com/in/markus17](http://www.linkedin.com/in/markus17)  
050-8536620 / 06-50258350

---

<div class="post-metadata">

**Author:** ![ramprasad\_ap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@ramprasad\_ap](https://www.ruby-forum.com/u/ramprasad_ap)\
**Post date:** [March 9, 2010, 1:19pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836/3 "2010-03-09T13:19:35Z")

</div>

Can you give me an example how to store an array in memcache

I am quiet new to ngnix , Do I require any extramodules or is memcache  
always a part of nignx

Posted at Nginx Forum:

> **[Re: How can I keep a large list in apache memory](https://forum.nginx.org/read.php?2,61798,61812#msg-61812)**
>
> Hello all, I am new to nginx , I am using ngnix as a Load balancer for two imap servers. All machines are RHEL5 64 bit The nginx calls an apache php script that determines if the user is on imap1 or imap2 by looking up a plain text file. which...

---

<div class="post-metadata">

**Author:** ![ramprasad\_ap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@ramprasad\_ap](https://www.ruby-forum.com/u/ramprasad_ap)\
**Post date:** [March 9, 2010, 1:38pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836/4 "2010-03-09T13:38:19Z")

</div>

Storing data in memcache can be done from almost any language available.  
You  
need to run a memcached server [1](http://memcached.org/) somewhere and connect to it from some  
program. Then you can simply set key/value pairs.

A PHP example:  
$m = new Memcache(‘host’);  
$m-\>set(‘key’, ‘value’);

If you set all your user/IP pairs in the cache, you can then retrieve  
them in  
your Nginx config. Make sure you have the memc module compiled in. It  
would  
also be a good idea to compile the eval module; with it, you can store  
the  
value in a variable.

Then, using that value (the IP address), you can select your backend.

On Tuesday 09 March 2010 13:19:04 ramprasad\_ap wrote:

> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

Markus J. - Technisch Architect - Buyways BV  
[http://www.linkedin.com/in/markus17](http://www.linkedin.com/in/markus17)  
050-8536620 / 06-50258350

---

<div class="post-metadata">

**Author:** ![ramprasad\_ap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@ramprasad\_ap](https://www.ruby-forum.com/u/ramprasad_ap)\
**Post date:** [March 9, 2010, 9:09pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836/5 "2010-03-09T21:09:40Z")

</div>

Is there a reason why you don’t want to use a database?

---

<div class="post-metadata">

**Author:** ![ramprasad\_ap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@ramprasad\_ap](https://www.ruby-forum.com/u/ramprasad_ap)\
**Post date:** [March 9, 2010, 10:21pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836/6 "2010-03-09T22:21:39Z")

</div>

James Matthews a Ã©crit :

> Is there a reason why you don’t want to use a database?

Memchached is _very_ fast, much faster than a database.

You should keep your data in a database and use a script to put it into  
memcache every hour/day.

---

<div class="post-metadata">

**Author:** ![ramprasad\_ap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@ramprasad\_ap](https://www.ruby-forum.com/u/ramprasad_ap)\
**Post date:** [March 9, 2010, 10:31pm UTC](https://www.ruby-forum.com/t/how-can-i-keep-a-large-list-in-apache-memory/184836/7 "2010-03-09T22:31:36Z")

</div>

On Tue, 2010-03-09 at 12:08 -0800, James Matthews wrote:

> Is there a reason why you don’t want to use a database?

memcached _is_ a database. It’s a key/value store. It’s not a  
_relational_ database, but the OP’s data isn’t relational, it’s  
key/value pairs, which is exactly what memcached was designed to handle.

Regards,  
Cliff
