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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.