Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1881 committed May 20, 2022
1 parent 1c6267c commit f317908
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ echo $curl->getCookie('laravel_session');
$curl::RAW
$curl::JSON
$curl::QUERY
$curl->getCurlError();

$curl->setDefault();
$curl->setMethod('GET');
$curl->setUrl('https://httpbin.org/get');
Expand All @@ -54,10 +54,8 @@ $curl->connect($url, $headers);
$curl->options($url, $headers);
$curl->trace($url, $headers);
$curl->exec();

$curl->setOpt(CURLOPT_URL, 'https://httpbin.org/get');
$curl->getOpt(CURLOPT_URL);
$curl->getInfo(CURLINFO_HTTP_CODE);
$curl->getInfos('http_code');
$curl->setDebug(true);
$curl->setUserAgent('Googlebot/2.1 (+http://www.google.com/bot.html)');
$curl->setCookieFile('./cookie.txt');
Expand All @@ -73,9 +71,15 @@ $curl->setMaxRedirect(5);
$curl->setProxy('https://username:password@127.0.0.1:8080/');
$curl->setProxyType(CURLPROXY_HTTPS);
$curl->setProxyAuth('username', 'password');
$curl->getResponse(false);
$curl->getRespJson(false);

$curl->find('search value', $source);

$curl->getOpt(CURLOPT_URL);
$curl->getInfo('http_code');
$curl->getCurlError();

$curl->getResponse();
$curl->getRespJson();
$curl->getBetween('<p>', '</p>');
$curl->getBetweens('<p>', '</p>');
$curl->getEffective();
Expand Down
21 changes: 11 additions & 10 deletions src/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct()
*/
public function getCurlError()
{
return isset($this->res->error) ?: $this->res->error;
return isset($this->res->error) && !\is_resource($this->req->ch) ?: $this->res->error;
}

/**
Expand Down Expand Up @@ -382,12 +382,12 @@ public function trace($url, $headers = [])
public function exec(): void
{
$response = curl_exec($this->req->ch);
$header_size = $this->getInfo(\CURLINFO_HEADER_SIZE);
$http_code = $this->getInfo(\CURLINFO_HTTP_CODE);
$effective_url = $this->getInfo(\CURLINFO_EFFECTIVE_URL);
$total_time = $this->getInfo(\CURLINFO_TOTAL_TIME);
$header_size = $this->curlGetInfo(\CURLINFO_HEADER_SIZE);
$http_code = $this->curlGetInfo(\CURLINFO_HTTP_CODE);
$effective_url = $this->curlGetInfo(\CURLINFO_EFFECTIVE_URL);
$total_time = $this->curlGetInfo(\CURLINFO_TOTAL_TIME);
$headers = trim(substr($response, 0, intval($header_size)));
$this->res->info = $this->getInfo();
$this->res->info = $this->curlGetInfo();
$this->res->code = $http_code;
$this->res->effective_url = $effective_url;
$this->res->total_time = $total_time;
Expand All @@ -401,6 +401,7 @@ public function exec(): void
$this->res->error = curl_error($this->req->ch);
}
curl_close($this->req->ch);
$this->req->ch = null;
}

/**
Expand Down Expand Up @@ -677,12 +678,12 @@ public function setUserAgent(string $useragent = null)
}

/**
* Curl getinfo function short version
* Curl getinfo function private short version
*
* @param mixed $opt
* @return mixed
*/
protected function getInfo($opt = null)
private function curlGetInfo($opt = null)
{
if (\is_null($opt)) {
return curl_getinfo($this->req->ch);
Expand All @@ -691,12 +692,12 @@ protected function getInfo($opt = null)
}

/**
* Curl getinfo function short version
* Curl getinfo function public short version
*
* @param mixed $opt
* @return mixed
*/
public function getInfos($key = null)
public function getInfo($key = null)
{
if (\is_null($key)) {
return $this->res->info;
Expand Down

0 comments on commit f317908

Please sign in to comment.