php - What functions can I use to contact another webpage (to send GET data) and set a timeout with? -
I need a function that I use to send some GET data to my script in order to contact it I can do for But I should be able to set timeout so that it loads for only a few seconds, then continue with the rest of the script. I know that I can easily use curls to do this, but I want to know if there are any alternatives?
You can specify a timeout when using standard file access functions (like For this, it is important that you file_get_contents ()
) Are:
& lt ;? Php $ opts = array ('http' = & gt; array ('method' = & gt; "GET", 'timeout' => 5)); $ Context = stream_context_create ($ opts); $ Fp = fopen ('http://www.example.com', 'r', false, $ reference); Fpassthru ($ FP); Fclose ($ FP); ? & Gt; For clarification on the
timeout
option, see. fopen ()
and consorts.
Comments
Post a Comment