-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_curl.php
41 lines (30 loc) · 1.47 KB
/
test_curl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?PHP
///////////////////////////////////////////////////////////////////////
function get_xml($url)
{
$headers[] = "Accept-Encoding: gzip";
//see: http://trog.qgl.org/20110729/differences-in-requesting-gziped-content-using-curl-in-php/
$ch = curl_init();
if (!$ch) {
$MainMSG="Kindly let Webmaster know, thru email: <a href=\"mailto:someone@someplace.com\"><b>Webmaster</b></a>";
#---- email the error ----> emailUs($url);
die("Couldn't initialize a cURL handle to access file: >>> ".$url. "<<<.<br>\n" .$MainMSG. "<br>");
exit(1); // A response code other than 0 is a failure
}
curl_setopt($ch, CURLOPT_URL, $url);
#curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,10); // The number of seconds to wait while trying to connect.
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // Timeout in seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT,'someone@someplace.com');
ob_start(); //--- Start buffering
$data = curl_exec($ch);
ob_end_clean(); //--- End buffering and clean output
curl_close($ch);
return $data;
}
///////////////////////////////////////////////////////////////////////
$url="http://www.someplace_unique.com/data/nwsweatherstory.kml";
$contents_of_XML_file=get_xml($url);
echo $contents_of_XML_file;
?>