YGGo/library/curl.php

45 lines
752 B
PHP
Raw Normal View History

2023-04-01 16:29:39 +00:00
<?php
class Curl {
private $_connection;
2023-04-03 01:47:31 +00:00
private $_response;
2023-04-01 16:29:39 +00:00
public function __construct(string $url) {
$this->_connection = curl_init($url);
curl_setopt($this->_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->_connection, CURLOPT_TIMEOUT, 5);
2023-04-03 01:47:31 +00:00
$this->_response = curl_exec($this->_connection);
2023-04-01 16:29:39 +00:00
}
public function __destruct() {
curl_close($this->_connection);
}
public function getError() {
if (curl_errno($this->_connection)) {
return curl_errno($this->_connection);
} else {
return false;
}
}
public function getCode() {
return curl_getinfo($this->_connection, CURLINFO_HTTP_CODE);
}
public function getContent() {
2023-04-03 01:47:31 +00:00
return $this->_response;
2023-04-01 16:29:39 +00:00
}
}