2017-06-28 00:31:40 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class TCP {
|
|
|
|
|
2017-06-29 22:13:25 +02:00
|
|
|
public static function http($url, $method='GET', $verifySSL=true, $timeOut=1)
|
2017-06-28 00:31:40 +02:00
|
|
|
{
|
|
|
|
if( function_exists('curl_version') ) {
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
// TRUE to include the header in the output
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
|
2017-06-29 22:13:25 +02:00
|
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
|
2017-06-28 00:31:40 +02:00
|
|
|
if($method=='POST') {
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
}
|
|
|
|
$output = curl_exec($ch);
|
|
|
|
if($output===false) {
|
|
|
|
Log::set('Curl error: '.curl_error($ch));
|
|
|
|
}
|
|
|
|
curl_close($ch);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$options = array(
|
|
|
|
'http'=>array(
|
2017-06-29 22:13:25 +02:00
|
|
|
'method'=>$method,
|
|
|
|
'timeout'=>$timeOut
|
2017-06-28 00:31:40 +02:00
|
|
|
),
|
|
|
|
"ssl"=>array(
|
|
|
|
"verify_peer"=>$verifySSL,
|
|
|
|
"verify_peer_name"=>$verifySSL
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$stream = stream_context_create($options);
|
|
|
|
$output = file_get_contents($url, false, $stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|