CDR in Realtime

I would like my program to block external connections after summed time in CDRs table in MySQL approaches some specific value.
One problem is that I don’t know when should I check that in my program. Can MySQL send signal to my program in some specific conditions? If it can’t is there any way to solve it in Asterisk only, without involving my program?
Second problem: CDR table is being updated only after end of call, so if - for example - I’ve got 5 minute to reach my limit, I still can make a 2 hours call without hanging up.

Sorry for my English, and I hope you could understand me.

Thanks in advance!