Skip to content

Commit

Permalink
Merge pull request #23 from skipperbent/development
Browse files Browse the repository at this point in the history
Optimisations
  • Loading branch information
skipperbent committed Dec 16, 2017
2 parents d27b2a9 + 968587e commit 8f7efb9
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/Pecee/Http/HttpRequest.php
Expand Up @@ -19,9 +19,6 @@ public function __construct($url = null)
throw new \ErrorException('This service requires the CURL PHP extension.');
}

// Disable PHP timeout
set_time_limit(0);

$this->reset();
$this->url = $url;
}
Expand Down Expand Up @@ -304,28 +301,31 @@ public function execute($return = true)
throw new \InvalidArgumentException('Missing required property: url');
}

if (strtolower($this->method) !== 'get') {
if (strtolower($this->method) === 'get' && count($this->getPostData()) > 0) {
$this->url .= ((strpos($this->url, '?') === false) ? '?' : '&');
}

curl_setopt($handle, CURLOPT_URL, $this->url);

$response = new HttpResponse($handle);
$response = new HttpResponse();

if ($this->contentType !== null) {
$this->addHeader('Content-Type: ' . $this->contentType);
}

if ($this->returnHeader) {
if ($this->returnHeader === true) {
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_HEADERFUNCTION, [&$response, 'parseHeader']);
}

if ($return) {
if ($return === true) {
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
}

if ($this->timeout) {
if ($this->timeout !== null && $this->timeout > 0) {
// Disable PHP timeout
set_time_limit($this->timeout);

curl_setopt($handle, CURLOPT_CONNECTTIMEOUT_MS, $this->timeout);
curl_setopt($handle, CURLOPT_TIMEOUT_MS, $this->timeout);
}
Expand Down Expand Up @@ -359,12 +359,12 @@ public function execute($return = true)
}

// Add headers
if (count($this->headers)) {
if (count($this->headers) > 0) {
curl_setopt($handle, CURLOPT_HTTPHEADER, $this->headers);
}

// Add custom curl options
if (count($this->options)) {
if (count($this->options) > 0) {
foreach ((array)$this->options as $option => $value) {
curl_setopt($handle, $option, $value);
}
Expand All @@ -375,6 +375,7 @@ public function execute($return = true)
$response->setInfo(curl_getinfo($handle))->setResponse($output, $this->returnHeader);

curl_close($handle);

unset($output, $handle);

return $response;
Expand Down

0 comments on commit 8f7efb9

Please sign in to comment.