Skip to content

Commit

Permalink
Explicitly set a default cURL timeout of 30 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
robhenley committed Dec 4, 2017
1 parent 5909248 commit a708821
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ That's it!

$ac = new ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY);

// Optionally set a curl timeout
// Adjust the default cURL timeout
$ac->set_curl_timeout(10);

$account = $ac->api("account/view");
Expand All @@ -67,7 +67,7 @@ Or just include everything in the same PHP file:
require_once("includes/ActiveCampaign.class.php");
$ac = new ActiveCampaign(ACTIVECAMPAIGN_URL, ACTIVECAMPAIGN_API_KEY);

// Optionally set a curl timeout
// Adjust the default cURL timeout
$ac->set_curl_timeout(10);

$account = $ac->api("account/view");
Expand Down
11 changes: 5 additions & 6 deletions includes/Connector.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

class AC_Connector {

const DEFAULT_TIMEOUT = 30;

public $url;
public $api_key;
public $output = "json";
private $timeout = NULL;
private $timeout = self::DEFAULT_TIMEOUT;

function __construct($url, $api_key, $api_user = "", $api_pass = "") {
// $api_pass should be md5() already
Expand Down Expand Up @@ -85,13 +87,10 @@ public function curl($url, $params_data = array(), $verb = "", $custom_method =
$debug_str1 .= "\$ch = curl_init();\n";
curl_setopt($request, CURLOPT_HEADER, 0);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_TIMEOUT, $this->timeout);
$debug_str1 .= "curl_setopt(\$ch, CURLOPT_HEADER, 0);\n";
$debug_str1 .= "curl_setopt(\$ch, CURLOPT_RETURNTRANSFER, true);\n";

if (!is_null($this->timeout)) {
curl_setopt($request, CURLOPT_TIMEOUT, $this->timeout);
$debug_str1 .= "curl_setopt(\$ch, CURLOPT_TIMEOUT, " . $this->timeout . ");\n";
}
$debug_str1 .= "curl_setopt(\$ch, CURLOPT_TIMEOUT, " . $this->timeout . ");\n";

if ($params_data && $verb == "GET") {
if ($this->version == 2) {
Expand Down

0 comments on commit a708821

Please sign in to comment.