how to monitor +20,000 addresses for new received transactions?

I have around 20000 generated addresses which I want to monitor for new transactions. More addresses should probably come. Customers should use every address only once but I would like to monitor already used addresses if some of them decide to transfer coins to “used” addresses.

These addresses are not in the online wallet, I have only addresses in the databases. Private keys are held offline.

That means that I do not want to monitor addresses from the local wallet but the addresses from databases.

A command should executed after a transaction is received (with enough confirmations). There are some monitor services which can send an email or call url after receiving a transaction for an address on the watchlist.

I would like to implement the same feature for my application without depending on external service.

I saw some questions and answers like:

How to know there is a new transaction? or
Monitor all transactions on bitcoin network – API

But what would be the most efficient way to do this? Is there a perl/php compatible way to do that?

One of topics from above links to https://bitcointalk.org/index.php?topic=89725.0 where Gavin is talking about some new features but I did not get how could I or whether I can use anything of this to monitor a high number of addresses. Sending every minute a batch RPC call with a few thousands addresses to bitcoind is probably not a solution :-(.

I hope that there is a elegant way to monitor the whole information stream (all incoming transactions and other incoming information) and react if it matches what I need.

Continue reading how to monitor +20,000 addresses for new received transactions?