title: file_get_contents() Timeout in php
body: <p>I know php doesn't give timeout option since it is running from server side. But my logic needs timeout. Please solve this case</p>
  
  <p><strong>My PHP:</strong> login.php :-</p>
  
  <pre><code>$forms_values = $_POST;
  $url = "http://sample.com/sample?params=$forms_values";
  $resp = file_get_contents($url);
  // It takes much time if sample.com is down.
  // so need to set time out here.
  $response = json_decode($resp, true);
  ....
  ....
  if ($response["auth"] == "yes"){
     header("index.php");
  }
  </code></pre>
  
  <p><strong>my html</strong> index.html :-</p>
  
  <pre><code>&lt;form action="login.php" method="post" id="clientLogin"&gt;
      &lt;div&gt;
          &lt;input id="username" placeholder="Email or Username" type="text" name="luser" size="30" value=""&gt;
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input id="passwd" placeholder="Password" type="password" name="lpasswd" size="30" value=""&gt;
      &lt;/div&gt;
  &lt;input class="btn" type="submit" value="Sign In"&gt;
  &lt;/form&gt;
  &lt;script type="text/javascript"&gt;
  //This is not working. and obviously delay will happen in server code 
  //and i cant get it in client side 
  
  $(window).load(function () {
       var submit = false;
       $("#clientLogin").submit(function(e) {
           alert("me after 1000 mili seconds");
            setTimeout(function(){
                alert("me after 1000 mili seconds");
                submit = true;
                $("#clientLogin").submit(); // if you want            
            }, 15000);
            if(!submit)
                e.preventDefault();
       });
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>This javascript is not working. and obviously delay will happen in server code and i cannot watch it from client side. </p>
  
  <p>so this is what i want. need to terminate submission process (from submit to rendering next page) if my <code>file_get_contents()</code> function is not responding for long.</p>
  
  <p><strong>Note</strong>:
  Please dont ask me to use curl, Because i am instructed to not use curl. 
  and i cant get it in client side </p>