Gossamer Forum
Home : General : Perl Programming :

Autoflush...

Quote Reply
Autoflush...
I have a weird problem. I am trying to call a page via a CGI script (to submit to search engine spiders). The weird thing is the code I have works fine until I set the $host variable to a dead link. An example of it being set to a dead URL s below;

Code:
my $EOL = "\015\012";
my $BLANK = $EOL x 2;

my $host = "www.googfgle.com";
my $document = "/addurl?type=submit&q=$url&dq=";

$remote = IO::Socket::INET->new( Proto => "tcp",
PeerAddr => $host,
PeerPort => "http(80)",
);
unless ($remote) { &error_submit("Google"); }
$remote->autoflush(1);
print $remote "GET $document HTTP/1.0" . $BLANK;
$good_engine .= qq~ <li>Google</li> ~;
Does anyone have any ideas?

The error log says;

Code:
[Sat Jul 21 07:00:40 2001] submitnew.cgi: Can't call method "autoflush" on an undefined value at /home/ace-webm/public_html/cgi-bin/submitnew.cgi line 94.
Prototype mismatch: sub main::head vs ($) at /home/ace-webm/public_html/cgi-bin/submitnew.cgi line 19
Prototype mismatch: sub main::head vs ($) at /home/ace-webm/public_html/cgi-bin/submitnew.cgi line 19
Any help you guys can offer will be greatly appreciated.

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Autoflush... In reply to
Anybody? Paul? Junko? Glennu? AnthroRules? ANYBODY!!!!!!! Frown

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Autoflush... In reply to
It is likely to be giving the error because IO::Socket won't be able to connect to a deadlink so it will die (unless you allow for this). That's what this means....

Can't call method "autoflush" on an undefined value

Try...

Code:
$remote = IO::Socket::INET->new( Proto => "tcp",
PeerAddr => $host,
PeerPort => "http(80)") or &submit_error("Google");
To get the full error you should pass $@ to the error sub.

You may need to add an exit in the error sub too.


Installations:http://www.wiredon.net/gt/

Quote Reply
Re: Autoflush... In reply to
Mmmm. I tried that, and it still doesn't work. Is there any other code that would do the same job? Basically, what I am trying to do is grab a page and put it into a variable.

Any ideas?

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Autoflush... In reply to
Is your error_submit routine calling exit?

Just glancing quickly, it would seem to me that if you're calling error_submit, then returning. That means that the autoflush method is being called, which is proving unsucessful since the socket connection didn't happen.

--mark

Quote Reply
Re: Autoflush... In reply to
Ok, I'm now using;

Code:
sub test
{

$cr = "\015\012";
$host = "www.direcerethit.com";
$path = "/index.html";

$host or return undef, "Can't parse host from url: $url";
$sock = new IO::Socket::INET ( PeerAddr => $host,
PeerPort => 80,
Proto => 'tcp',
Type => SOCK_STREAM,
) || &error_submit("Google"); exit;
$sock->autoflush(1);
$sock->timeout(5);
print $sock "GET $path HTTP/1.0$cr";
print $sock "Host: $host$cr";
print $sock "User-Agent: Ace Submit (http://www.ace-installer.com/)$cr$cr";
my $response = <$sock>;
close $sock;

$good_engine .= qq~ <li>Direct Hit</li> ~;
print "Done engine 3";

}
I've added some extra stuff at the bottom of each sub (currently 3 subs, with one of them leading to a dead URL) so that I know how far the script managed to get. So far I can see that is the $host is unavailable, it will just stop there. The error sub is;

Code:
# Error to push the errors into the unsubmitted subroutine...
sub error_submit
{
my ($error) = shift;
$error_engine .= qq~ <li>$error</li> \n~;
}
I've also tried the error sub with an exit; at the end of it, but that didn't work either Frown

At least we are getting somewhere with it (no more bloody errors saying it can't flush...), but I really want to get this error checking thing done. Basically I don't want everyone who will use it to get 500 IS Errors every time the server they are trying to get the page from goes down Frown

Thanks for all the help so far!

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Autoflush... In reply to
In Reply To:
|| &error_submit("Google"); exit;
You are always going to exit. =) Try:

or return error_submit('Google');

That would probably be better (assuming this is in a subroutine).

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Autoflush... In reply to
Mmm...I tried that (have a look at http://www.vgacd.com/...s.com&url=wewewe). Now it only submits to the two first subs before, and then after it when it gets to this sub it just stops Frown

Any other ideas?

Oh, and I'm privalidged by 'The Great Alex' answering a post of mine....lol

Andy

webmaster@ace-installer.com
http://www.ace-installer.com