Skip to content

Commit 3978921

Browse files
committed
Update JsonRPCClient.php
Add functions to enable or disable the use of cURL when performs a jsonRCP request. In case of cURL is callable but may not piratically usable. For example, being blocked by firewall.
1 parent 7022f31 commit 3978921

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/org/jsonrpcphp/JsonRPCClient.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ class JsonRPCClient
6060
* @var boolean
6161
*/
6262
private $notification = false;
63+
64+
/**
65+
* If false, requests will be forced to use fopen() instead.
66+
* This option is specific in case of cURL is callable but may not practically unsable.
67+
*
68+
* @var boolean
69+
*/
70+
private $enableCurl = true;
6371

6472
/**
6573
* Takes the connection parameters
@@ -141,7 +149,7 @@ public function __call($method, $params)
141149
);
142150
$context = stream_context_create($opts);
143151

144-
if (is_callable('curl_init')) {
152+
if ($this->enableCurl && is_callable('curl_init')) {
145153
// use curl when available; solves problems with allow_url_fopen
146154
$ch = curl_init($this->url);
147155
curl_setopt($ch, CURLOPT_POST, 1);
@@ -185,4 +193,20 @@ public function __call($method, $params)
185193
return true;
186194
}
187195
}
196+
197+
/**
198+
* Enable cURL when performs a jsonRCP request.
199+
*/
200+
public function enableCurl()
201+
{
202+
$this->enableCurl = true;
203+
}
204+
205+
/**
206+
* Disable cURL when performs a jsonRCP request.
207+
*/
208+
public function disableCurl()
209+
{
210+
$this->enableCurl = false;
211+
}
188212
}

0 commit comments

Comments
 (0)