Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8062501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:41:27+00:00 2026-06-05T10:41:27+00:00

I am using LWP to download content from web pages, and I would like

  • 0

I am using LWP to download content from web pages, and I would like to limit the amount of time it waits for a page. This is accomplished in LWP like this:

my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->get($url);

And this works fine, except for whenever the timeout reaches its limit, it just dies, and I can’t continue on with the script. I’d really like to handle this timeout properly so that I can record that the URL had a timeout and then move on to my next one. Does anyone know how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:41:29+00:00Added an answer on June 5, 2026 at 10:41 am

    LWP::Agent‘s get() returns a HTTP::Response object that you can use for checking errors:

    use LWP::Agent;
    use HTTP::Status ();
    
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    my $response = $ua->get($url);
    
    if ($response->is_error) {
        printf "[%d] %s\n", $response->code, $response->message;
    
        # record the timeout
        if ($response->code == HTTP::Status::HTTP_REQUEST_TIMEOUT) {
            ...
        }
    }
    

    Btw, the better practice nowadays is to use Try::Tiny instead of eval {...}. It gives you try {...} catch {...}. and it resolves some problems with checking if $@ (see the background section in the Try::Tiny documentation).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am fetching some pages over the Web using Perl's LWP::UserAgent and would like
Using Flex 3, I would like to take an image snapshot such as this:
I'm trying to crawl this page using Perl LWP: http://livingsocial.com/cities/86/deals/138811-hour-long-photo-session-cd-and-more I had code that
Using a restful resource in Rails, I would like to be able to insert
I am trying to download a file from a site using perl. I chose
I wrote a quick script to download files using LWP::Simple library and its getstore()
I am having some issue here using LWP::Simple to get ftp site content in
I'm trying to fetch Wikipedia pages using LWP::Simple , but they're not coming back.
When using the get method from LWP::UserAgent with :content_file and :content_cb set but without
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.