Skip to content

Commit 697f8e8

Browse files
committed
Fix #922 for php_uname disabled
1 parent 990efbb commit 697f8e8

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Elasticsearch/Connections/Connection.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ class Connection implements ConnectionInterface
112112

113113
private $lastRequest = array();
114114

115+
/**
116+
* @var string
117+
*/
118+
private $OSVersion = null;
119+
115120
public function __construct(
116121
callable $handler,
117122
array $hostDetails,
@@ -145,8 +150,8 @@ public function __construct(
145150
$this->headers['User-Agent'] = [sprintf(
146151
"elasticsearch-php/%s (%s %s; PHP %s)",
147152
Client::VERSION,
148-
php_uname("s"),
149-
php_uname("r"),
153+
PHP_OS,
154+
$this->getOSVersion(),
150155
phpversion()
151156
)];
152157

@@ -543,6 +548,22 @@ protected function getCurlRetryException(array $request, array $response): Elast
543548
return $exception;
544549
}
545550

551+
/**
552+
* Get the OS version using php_uname if available
553+
* otherwise it returns an empty string
554+
*
555+
* @see https://github.com/elastic/elasticsearch-php/issues/922
556+
*/
557+
private function getOSVersion(): string
558+
{
559+
if ($this->OSVersion === null) {
560+
$this->OSVersion = strpos(strtolower(ini_get('disable_functions')), 'php_uname') !== false
561+
? ''
562+
: php_uname("r");
563+
}
564+
return $this->OSVersion;
565+
}
566+
546567
/**
547568
* Construct a string cURL command
548569
*/

0 commit comments

Comments
 (0)