Okay, I tried to sanitize the code as much as possible. Was initially reluctant to do so but I hafta help y'all help me, and this is the best way. And yes, I know I'm a terrible coder:
#!/usr/bin/perl use MIME::Base64; use Encode qw(encode); use DBI; use DBI qw(:sql_types); require HTTP::Request; require HTTP::Response; use HTTP::Async; #HTTP::Async timout is broken by default. Check the cpan page for how + to fix. It's in the bugs page. my $async = HTTP::Async->new(timeout=>5,slots=>100); use List::MoreUtils; use strict; open PIDFILE, ">/usr/path/pidfile" or die $!; print PIDFILE $$; close PIDFILE; #definition of variables my $db="databasename"; my $host="localhost"; my $user="username"; my $password="password"; my $verbose_logging = -1; while (1 == 1) { sleep rand 3; my @sites; my @db_row; my @response_array; #connect to MySQL database my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host", $user, $password) or die "Can't connect to database: $DBI::err +str\n"; #prepare the query my $sth = $dbh->prepare( "SELECT `page_url`, `url2`, `idx`, `date_time +`, `userid` FROM `queue` LIMIT 100"); #execute the query $sth->execute( ); ## Retrieve the results of a row of data and print while ( my @row = $sth->fetchrow_array( ) ) { #set counter push(@sites, $row[0]); push @db_row, ([$row[0], $row[1], $row[2], $row[3], $row[4]]); } foreach my $site(@sites) { $async->add( HTTP::Request->new( GET => $site ) ); } # Do some processing with $response #while ( my ( $response, $id ) = $async->wait_for_next_response) # { while ( $async->not_empty ) { if ( my ($response, $id) = $async->wait_for_next_response ) { # deal with $response print $async->info; my $content = $response->decoded_content; #Needs to be reencoded #async assigns ID's for all the requests, but they begin with 1, wh +ereas, rows begin with 0 with #sql requests. We'll need to decrement them to make sure everythin +g matches up when we #pick the elements out of the nested array my $result_row = ($id - 1); my $urlcount = 0; #Counts the number occurances of the input in the html content $urlcount++ while ($content =~ m/$db_row[$result_row][1]/gi); #encodes the content so that we can easily store to the DB for lat +er referencing. $content = encode_base64(encode("UTF-8", $content)); my $insert = "INSERT INTO cheker (`active`,`page_url`,`url2`,`date +_time`,`userid`,`html_source`) VALUES ($urlcount,'$db_row[$result_row +][0]','$db_row[$result_row][1]','$db_row[$result_row][3]','$db_row[$r +esult_row][4]','$content');"; my $QueueExecute = $dbh->prepare($insert); $QueueExecute->execute( ); warn "Problem in retrieving results", $sth->errstr( ), "\n" if $QueueExecute->err( ); if ($verbose_logging >= 0) { print "Inserted record into checker\n"; } my $delete = "DELETE FROM queue WHERE `idx` = '$db_row[$result_row +][2]';"; my $QueueExecute = $dbh->prepare($delete); $QueueExecute->execute( ); if ($verbose_logging >= 0) { print "Deleted row from queue\n"; } warn "Problem in retrieving results", $sth->errstr( ), "\n" if $QueueExecute->err( ); warn "Problem in retrieving results", $sth->errstr( ), "\n" if $sth->err( ); } else { next; } } #$result_row++; # my $result_row = 0; # my $response_row = 1; }

In reply to Re^2: HTTP:Async weirdness by schnibitz
in thread HTTP:Async weirdness by schnibitz

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.