Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

How to make an HTTP request with an equivalent of curl's --max-time?

by Cody Fendant (Hermit)
on Jan 14, 2015 at 06:04 UTC ( [id://1113194]=perlquestion: print w/replies, xml ) Need Help??

Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I'm grabbing data from a special Twitter firehose-type URL.

It will send information indefinitely*, so in order to manage the amount of data received by the script, it's recommended to use the maximum-time option.

Here's what I'm doing, a system() call containing:

/usr/bin/curl --request 'GET' 'https://stream.twitter.com/1.1/statuses/sample.json' --max-time 180 --header 'Authorization: $header'

Where $header is some OAuth magic.

So, is it possible to do this without the shell-out to curl and keep it all within Perl?

As far as I can see, that maximum time option isn't directly related to HTTP Headers, it's curl-specific.

* Updated to add documentation on this "indefinitely" thing. From the Twitter documentation::

To connect to the Streaming API, form a HTTP request and consume the resulting stream for as long as is practical. Our servers will hold the connection open indefinitely, barring server-side error, excessive client-side lag, network hiccups, routine server maintenance or duplicate logins.

Replies are listed 'Best First'.
Re: How to make an HTTP request with an equivalent of curl's --max-time?
by atcroft (Abbot) on Jan 14, 2015 at 06:11 UTC

    My first thought would be to wrap the call in an eval{} block, and set an alarm(), similar to the docs for the alarm function.

    Hope that helps.

Re: How to make an HTTP request with an equivalent of curl's --max-time?
by blindluke (Hermit) on Jan 14, 2015 at 06:51 UTC
Re: How to make an HTTP request with an equivalent of curl's --max-time?
by Anonymous Monk on Jan 14, 2015 at 09:01 UTC
    Use :content_cb option, and inside it perform a max-time check ... lwp has built in max-size check
Re: How to make an HTTP request with an equivalent of curl's --max-time?
by Anonymous Monk on Jan 14, 2015 at 07:09 UTC
    Where is the documentation for this thing?

      For the max-time option? It's in the manpage for curl.

      $ man curl (...) -m, --max-time <seconds> Maximum time in seconds that you allow the whole operation to ta +ke. This is useful for preventing your batch jobs from hanging for h +ours due to slow networks or links going down. Since 7.32.0, this option accepts decimal values, but the actual timeout will +decrease in accuracy as the specified timeout increases in decimal precis +ion. See also the --connect-timeout option. If this option is used several times, the last one will be used. (...)

      - Luke

        For the max-time option? It's in the manpage for curl.

        No, not for the self-explanatory option, for the magic url that is immune to regular HTTP GET, that it needs a client induced timeout

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1113194]
Approved by atcroft
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2026-01-25 03:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (126 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.