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 6024691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:11:33+00:00 2026-05-23T04:11:33+00:00

I am trying to properly handle fopen when the remote site or server is

  • 0

I am trying to properly handle fopen when the remote site or server is down..I “think” the script below is not handling it gracefully. It seems if the remote site is down, then the site that tries to run this script doesn’t load as well…So what I am trying to do is prevent that somehow. How can I tell it to stop trying if the remote server takes too long?

if ($handle = @fopen('http://test.com/versions.xml','r')) {
    $versions = fread($handle, 1024);
    fclose($handle);
} elseif (function_exists('curl_init')) {
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, 'http://test.com/versions.xml');
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    $versions = curl_exec($ch);
    curl_close($ch);    
}
  • 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-05-23T04:11:34+00:00Added an answer on May 23, 2026 at 4:11 am

    Ok I found the answer to this…Simply do the following..

    $context = stream_context_create(array('http'=>array('timeout'=>2)));
    if ($handle = @fopen('http://test.com/versions.xml','r',false,$context))... 
    

    This will set the timeout to 2 seconds…

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

Sidebar

Related Questions

I am trying to handle two different WebException 's properly. Basically they are handled
I'm trying to use JQuery Slidetoggle functionality, but not able to use properly. The
I've been trying to figure out how to properly accommodate how to handle 'Identity'
I am currently trying to learn how to properly handle multi-threaded access to Collections,
I'm trying to catch as many errors as possible in PHP and properly handle
I'm not very good at SQL, so I've been trying to just handle this
I have an MVC3 site that needs to handle user posts. I am trying
I'm trying to properly handle and return a 404 for this URL: http://localhost:2867/dd./xml (notice
I'm trying to properly encapsulate a class A, which should only be operated on
I'm trying to figure out how to properly serialize my XmlDocument and send it

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.