Skip to content

Commit

Permalink
Merge pull request #241 from lart2150/master
Browse files Browse the repository at this point in the history
Persist curl resource between requests
  • Loading branch information
lesstif authored Mar 23, 2019
2 parents fd17ead + fdf3629 commit e2cd96a
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/JiraClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function __construct(ConfigurationInterface $configuration = null, Logger
}

$this->http_response = 200;

$this->curl = curl_init();
}

/**
Expand Down Expand Up @@ -183,7 +185,8 @@ public function exec($context, $post_data = null, $custom_request = null, $cooki
$this->log->info("Curl $custom_request: $url JsonData=".json_encode($post_data, JSON_UNESCAPED_UNICODE));
}

$ch = curl_init();
curl_reset($this->curl);
$ch = $this->curl;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);

Expand Down Expand Up @@ -233,7 +236,6 @@ public function exec($context, $post_data = null, $custom_request = null, $cooki
if (!$response) {
$this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$body = curl_error($ch);
curl_close($ch);

/*
* 201: The request has been fulfilled, resulting in the creation of a new resource.
Expand All @@ -253,8 +255,6 @@ public function exec($context, $post_data = null, $custom_request = null, $cooki
// if request was ok, parsing http response code.
$this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

// don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION
if ($this->http_response != 200 && $this->http_response != 201) {
throw new JiraException('CURL HTTP Request Failed: Status Code : '
Expand All @@ -276,7 +276,8 @@ public function exec($context, $post_data = null, $custom_request = null, $cooki
*/
private function createUploadHandle($url, $upload_file)
{
$ch = curl_init();
curl_reset($this->curl);
$ch = $this->curl;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);

Expand Down Expand Up @@ -419,7 +420,6 @@ protected function closeCURLHandle(array $chArr, $mh, $body, $result_code)
foreach ($chArr as $ch) {
$this->log->debug('CURL Close handle..');
curl_multi_remove_handle($mh, $ch);
curl_close($ch);
}
$this->log->debug('CURL Multi Close handle..');
curl_multi_close($mh);
Expand Down Expand Up @@ -533,7 +533,8 @@ public function download($url, $outDir, $file, $cookieFile = null)
{
$file = fopen($outDir.DIRECTORY_SEPARATOR.$file, 'w');

$ch = curl_init();
curl_reset($this->curl);
$ch = $this->curl;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);

Expand Down Expand Up @@ -563,7 +564,6 @@ public function download($url, $outDir, $file, $cookieFile = null)
if (!$response) {
$this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$body = curl_error($ch);
curl_close($ch);
fclose($file);

/*
Expand All @@ -583,8 +583,6 @@ public function download($url, $outDir, $file, $cookieFile = null)
} else {
// if request was ok, parsing http response code.
$this->http_response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);
fclose($file);

// don't check 301, 302 because setting CURLOPT_FOLLOWLOCATION
Expand Down

0 comments on commit e2cd96a

Please sign in to comment.