Previously, I wrote the example to set timeout for fopen function. But it is not practical way to put timeout, because the configuration data is also modified by that function.
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\nHost: " . $host . "\n\n");
while (!feof($fp))
{
$buf .= fgets($fp, 128);
}
$lines = split("\n", $buf);
$data = $lines[count($lines)-1];
fclose($fp);
} else {
# enter error handing code here
}
echo $data;
$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\nHost: " . $host . "\n\n");
while (!feof($fp))
{
$buf .= fgets($fp, 128);
}
$lines = split("\n", $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.
Another posts included in "PHP"
| ASCII Artwork Generator from image file (0) | 2008/09/23 |
| How to delete file on certain path ? (0) | 2008/10/01 |
| How to remove HTML tags in text string? (0) | 2009/08/05 |
| How to put timeout when opening URL by fopen ? (0) | 2008/03/31 |
| How to convert W3C Date Time Format ? (0) | 2008/02/28 |
| Get the actual filesize for a size above 2GB in Windows (0) | 2008/02/24 |
| ISO 8601 format time format string conversion (0) | 2008/02/13 |
| How to download a file from a certain URL to server ? (0) | 2008/01/21 |
Trackback : Cannot send a trackbact to this post.
-
Subject Vicodin.
2008/12/18 10:08
Vicodin withdrawls. Vicodin no prescription. Vicodin. Dangers of vicodin. Buy vicodin. Easing symptoms of vicodin withdrawal.

Prev

Rss Feed