Dear Monks,
I am trying to write a script that will open a TCP socket, perform an HTTP get and display the server replay.
The script should fork and all the children should use the same socket (using HTTP version 1.1 and keep alive).
The script below works fine but each process open a new socket which adds unnecessary delay (I am using Time::HiRes to calculate the total time to get 10 pages and save the content).
How can I improve the script so all the forked process wil use the same TCP socket?
Your help please…
#!/usr/bin/perl
use LWP::Simple;
use Time::HiRes qw(time);
use Parallel::ForkManager;
my $filename = "/tmp/result.log";
while ($z <=200) {
$z++;
my $i = 1;
my $pm = new Parallel::ForkManager(20);
my $t0 = time;
my $num = 10;
unlink("$filename");
open FH, ">:utf8", $filename;
while ($i < $num) {
$i++;
$pm->start and next;
$contents = get("http://test.com/b.php?page=$i");
print FH "$contents\?";
$pm->finish;
}
$pm->wait_all_children;
$elapsed = time - $t0;
print "$elapsed elapsed\n";
}
Regards,
Adi.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.