Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Im a newbie with scripting, and learn fast, (sorta) however Im far from understanding enough to optimize for memory leaks, in fact im finding it hard to actually get alot of info on the subject. Till I found your amazing site. Im hoping that some of your perl gurus will take a quick moment to look over this very very short snippet of code and see if anything glars as a memory leak, according to my hosting service: "This script is periodically consuming all 2GB of your RAM. This causes the system to then use harddrive space for additional RAM or commonly known as SWAP space. This then is consumed as well. Once this occurs, their is no RAM left on the box to handle existing processes. The CPU tries to handle the load overheating and then logging events to the system log before either crashing the system or shutting down to protect itself." The following is the code in question:
#!/usr/bin/perl use Carp; use vars qw(%config %category %form %super); require "/var/www/vhosts/mysite.com/cgi-bin/categories.cgi"; $config{'basepath'} = '/var/www/vhosts/mysite.com/cgi-bin/'; $config{'bluedir'} = 'register'; my $key; my $numusers = 1; opendir THEDIR, "$config{'basepath'}$config{'bluedir'}"; my @allfiles = grep -T, map "$config{'basepath'}$config{'bluedir'}/$_" +, readdir THEDIR; closedir THEDIR; $numusers = $numusers + @allfiles; my $totalfiles = 100; foreach $key (sort keys %category) { opendir THEDIR, "$config{'basepath'}$key"; my @allfiles = grep -T, map "$config{'basepath'}$key/$_", readdir THED +IR; closedir THEDIR; $totalfiles = $totalfiles + @allfiles; } #################################### print "Content-type: text/html\n\n"; #print "<center><font face=arial size=2><b>There are currently<font co +lor=FF0000> $numusers</font> registered users and<font color=FF0000> +$totalfiles</font><font color=000000> open auctions.</font></b></cent +er>\n"; print <<"EOF"; <div align=center> <center> <table border=0 cellpadding=0 cellspacing=0 width=100\%> <tr> <td width=100\% valign=middle align=center height=15></td> </tr> <tr> <td width=100\% valign=middle align=center height=20><font face= +Arial size=2><b>There are currently:</b></font></td> </tr> <tr> <td width=100\% valign=middle align=center height=15></td> </tr> <tr> <td width=100\% valign=middle align=center><img src=/images/user +s.gif> &nbsp;&nbsp;<font face=Arial size=2><b><font color=#FF0000>$nu +musers</font> registered users.</b></font></td> </tr> <tr> <td width=100\% valign=middle align=center height=0></td> </tr> <tr> <td width=100\% valign=middle align=center><img src=/images/auci +.gif> &nbsp;&nbsp;<font face=Arial size=2><b><font color=#FF0000>$tot +alfiles</font> open auctions.</b></font></td> </tr> <tr> <td width=100\% valign=middle align=center height=15></td> </tr> </table> </center> </div> EOF 1;

In reply to Poorly written script by Baffled

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found