How to limit by Timeout when opening URL ? | ||
| ||
| Here's another way to achieve the same function. $query = "http://kurapa.com/api/?lic=" . $license_key . "&i=" . $ipaddress; $url = parse_url($query); $host = $url["host"]; $path = $url["path"] . "?" . $url["query"]; $timeout = 1; $fp = fsockopen ($host, 80, $errno, $errstr, $timeout) or die('Can not open connection to server.'); if ($fp) { fputs ($fp, "GET $path HTTP/1.0 Host: " . $host . " "); while (!feof($fp)) { $buf .= fgets($fp, 128); } $lines = split(" ", $buf); $data = $lines[count($lines)-1]; fclose($fp); } else { # enter error handing code here } echo $data; As you can see above, I used fsockopen function to put timeout. | ||
| | ||
| |