Skip to content

Commit b31ec55

Browse files
committed
Merge pull request #4 from dajero/move-context-creation
Only create stream_context if curl is not used. Thank you, @dajero
2 parents acbd901 + 1387b86 commit b31ec55

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/org/jsonrpcphp/JsonRPCClient.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,6 @@ public function __call($method, $params)
140140
}
141141

142142
// performs the HTTP POST
143-
$opts = array(
144-
'http' => array(
145-
'method' => 'POST',
146-
'header' => 'Content-type: application/json',
147-
'content' => $request
148-
)
149-
);
150-
$context = stream_context_create($opts);
151-
152143
if ($this->enableCurl && is_callable('curl_init')) {
153144
// use curl when available; solves problems with allow_url_fopen
154145
$ch = curl_init($this->url);
@@ -164,6 +155,15 @@ public function __call($method, $params)
164155
throw new \Exception('Unable to connect to ' . $this->url);
165156
}
166157
} else {
158+
$opts = array(
159+
'http' => array(
160+
'method' => 'POST',
161+
'header' => 'Content-type: application/json',
162+
'content' => $request
163+
)
164+
);
165+
$context = stream_context_create($opts);
166+
167167
if ($fp = fopen($this->url, 'r', false, $context)) {
168168
$response = '';
169169
while ($row = fgets($fp)) {

0 commit comments

Comments
 (0)