Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit f317908

Browse files
committed
fix
1 parent 1c6267c commit f317908

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ echo $curl->getCookie('laravel_session');
3737
$curl::RAW
3838
$curl::JSON
3939
$curl::QUERY
40-
$curl->getCurlError();
40+
4141
$curl->setDefault();
4242
$curl->setMethod('GET');
4343
$curl->setUrl('https://httpbin.org/get');
@@ -54,10 +54,8 @@ $curl->connect($url, $headers);
5454
$curl->options($url, $headers);
5555
$curl->trace($url, $headers);
5656
$curl->exec();
57+
5758
$curl->setOpt(CURLOPT_URL, 'https://httpbin.org/get');
58-
$curl->getOpt(CURLOPT_URL);
59-
$curl->getInfo(CURLINFO_HTTP_CODE);
60-
$curl->getInfos('http_code');
6159
$curl->setDebug(true);
6260
$curl->setUserAgent('Googlebot/2.1 (+http://www.google.com/bot.html)');
6361
$curl->setCookieFile('./cookie.txt');
@@ -73,9 +71,15 @@ $curl->setMaxRedirect(5);
7371
$curl->setProxy('https://username:password@127.0.0.1:8080/');
7472
$curl->setProxyType(CURLPROXY_HTTPS);
7573
$curl->setProxyAuth('username', 'password');
76-
$curl->getResponse(false);
77-
$curl->getRespJson(false);
74+
7875
$curl->find('search value', $source);
76+
77+
$curl->getOpt(CURLOPT_URL);
78+
$curl->getInfo('http_code');
79+
$curl->getCurlError();
80+
81+
$curl->getResponse();
82+
$curl->getRespJson();
7983
$curl->getBetween('<p>', '</p>');
8084
$curl->getBetweens('<p>', '</p>');
8185
$curl->getEffective();

src/Curl.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __construct()
8181
*/
8282
public function getCurlError()
8383
{
84-
return isset($this->res->error) ?: $this->res->error;
84+
return isset($this->res->error) && !\is_resource($this->req->ch) ?: $this->res->error;
8585
}
8686

8787
/**
@@ -382,12 +382,12 @@ public function trace($url, $headers = [])
382382
public function exec(): void
383383
{
384384
$response = curl_exec($this->req->ch);
385-
$header_size = $this->getInfo(\CURLINFO_HEADER_SIZE);
386-
$http_code = $this->getInfo(\CURLINFO_HTTP_CODE);
387-
$effective_url = $this->getInfo(\CURLINFO_EFFECTIVE_URL);
388-
$total_time = $this->getInfo(\CURLINFO_TOTAL_TIME);
385+
$header_size = $this->curlGetInfo(\CURLINFO_HEADER_SIZE);
386+
$http_code = $this->curlGetInfo(\CURLINFO_HTTP_CODE);
387+
$effective_url = $this->curlGetInfo(\CURLINFO_EFFECTIVE_URL);
388+
$total_time = $this->curlGetInfo(\CURLINFO_TOTAL_TIME);
389389
$headers = trim(substr($response, 0, intval($header_size)));
390-
$this->res->info = $this->getInfo();
390+
$this->res->info = $this->curlGetInfo();
391391
$this->res->code = $http_code;
392392
$this->res->effective_url = $effective_url;
393393
$this->res->total_time = $total_time;
@@ -401,6 +401,7 @@ public function exec(): void
401401
$this->res->error = curl_error($this->req->ch);
402402
}
403403
curl_close($this->req->ch);
404+
$this->req->ch = null;
404405
}
405406

406407
/**
@@ -677,12 +678,12 @@ public function setUserAgent(string $useragent = null)
677678
}
678679

679680
/**
680-
* Curl getinfo function short version
681+
* Curl getinfo function private short version
681682
*
682683
* @param mixed $opt
683684
* @return mixed
684685
*/
685-
protected function getInfo($opt = null)
686+
private function curlGetInfo($opt = null)
686687
{
687688
if (\is_null($opt)) {
688689
return curl_getinfo($this->req->ch);
@@ -691,12 +692,12 @@ protected function getInfo($opt = null)
691692
}
692693

693694
/**
694-
* Curl getinfo function short version
695+
* Curl getinfo function public short version
695696
*
696697
* @param mixed $opt
697698
* @return mixed
698699
*/
699-
public function getInfos($key = null)
700+
public function getInfo($key = null)
700701
{
701702
if (\is_null($key)) {
702703
return $this->res->info;

0 commit comments

Comments
 (0)