I have a script on my server that processes a large flat-file. The script takes about a second or so to process the information and return it to the user. Considering the possible hazard in having many people use the script, I decided to code some countermeasures to prevent the users from reloading too many times in a row and give them a limit per day.
This works great, except for the fact that I store their IP, last request time, and number of visits in an XML file. Right now, with only 20 or so visitors the file is at 2kb. When more unique users visit this page, the XML file will continue to grow. Will this become a future bottleneck? It would be really ironic if a security measure intended to relieve strain on a server causes more than it prevents.
The XML looks like this:
<opt> <ip0.0.0.0 visits="1" time="1043393316" /> <ip127.0.0.1 visits="5" time="1043370125" /> ...
The code for checking the XML looks like this:
my $xs = XML::Simple->new(); my $xmlf = './data/rsn_users.xml'; my $ip = 'ip' . $ENV{REMOTE_ADDR}; my $config = $xs->XMLin($xmlf); my ($time, $visits); if(exists $config->{$ip}){ $time = $config->{$ip}{'time'}; $visits = $config->{$ip}{'visits'}; } else{ $config->{$ip}{'time'} = time()-21; $config->{$ip}{'visits'} = 0; $time = $config->{$ip}{'time'}; $visits = $config->{$ip}{'visits'}; } if($time < time()-86400){ $config->{$ip}{'visits'} = $visits = 0; } if($time > time()-20){ print "Content-type: text/html\n\n"; print qq[You reloaded too soon!<br /> Your IP: $ip<br />Last visit: $config->{$ip}{'time'}<br /> Number of Visits: $config->{$ip}{'visits'}]; exit; } if($visits > 15){ print "Content-type: text/html\n\n"; print qq[You are over the allowed number of visits per day!<br /> Wait 86400 seconds (one day), then reload.<br /> Your IP: $ip<br />Last visit: $config->{$ip}{'time'} <br />Number of Visits: $config->{$ip}{'visits'}]; exit; }
Any suggestions?
Striving for better code,
John J Reiser
newrisedesigns.com
In reply to When does XML get to be too much? by newrisedesigns
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |