Skip to content

Commit 26b4f08

Browse files
authored
Merge pull request #19 from homiedopie/feature/LNX-285
LNX-285 - Update php-http/socket-client and update client constructor signature
2 parents 30f93d4 + c98c005 commit 26b4f08

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"psr/log": "~1.0",
1111
"guzzlehttp/guzzle": "^6.3",
1212
"guzzlehttp/psr7": "^1.6",
13-
"php-http/socket-client": "^1.4",
13+
"php-http/socket-client": "^2.0",
1414
"php-http/message": "^1.8"
1515
},
1616
"autoload": {

src/Stackify/Log/Transport/AgentSocketTransport.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Http\Client\Socket\Client;
77
use Http\Message\MessageFactory\GuzzleMessageFactory;
88
use Stackify\Log\Transport\Config\Agent as Config;
9+
use Http\Client\Socket\Exception\ConnectionException as HttpClientSocketConnectionException;
910

1011
/**
1112
* This transport requires Stackify Agent to be installed and running on the same machine
@@ -17,36 +18,64 @@ class AgentSocketTransport extends AbstractApiTransport
1718
const ERROR_WRITE = 'Cannot write to domain socket at %s. Is Stackify Agent installed and running?';
1819
const ERROR_CONNECT = 'Cannot connect to domain socket at %s. Is Stackify Agent installed and running? [Error code: %d] [Error message: %s]';
1920

21+
/**
22+
* Constructor
23+
*
24+
* @param array $options Socket transport options
25+
*/
2026
public function __construct(array $options = array())
2127
{
2228
parent::__construct('NONE', $options);
2329
}
2430

31+
/**
32+
* Transport name
33+
*
34+
* @return string
35+
*/
2536
protected function getTransportName()
2637
{
2738
return 'AgentSocketTransport';
2839
}
2940

41+
/**
42+
* Flush data to socket
43+
*
44+
* @param mixed $data Log message
45+
*
46+
* @return void
47+
*/
3048
protected function send($data)
3149
{
3250
try {
3351
if (!empty($data)) {
3452
$messageFactory = new GuzzleMessageFactory();
35-
$client = new Client($messageFactory, array('remote_socket' => 'unix://' . $this->getDomainSocketPath()));
53+
$client = new Client($messageFactory, null, array('remote_socket' => 'unix://' . $this->getDomainSocketPath()));
3654

37-
$request = $messageFactory->createRequest('POST', 'http://log',
38-
array('Content-Type' => 'application/json', 'Content-Length' => strlen($data)),
39-
$data);
55+
$request = $messageFactory->createRequest(
56+
'POST',
57+
'http://log',
58+
array(
59+
'Content-Type' => 'application/json',
60+
'Content-Length' => strlen($data)
61+
),
62+
$data
63+
);
4064

4165
$response = $client->sendRequest($request);
4266

4367
if ($response->getStatusCode() != 200) {
44-
$this->logError(self::ERROR_WRITE, $this->getDomainSocketPath());
68+
$this->logError(
69+
self::ERROR_WRITE,
70+
$this->getDomainSocketPath()
71+
);
4572
}
4673
}
4774

4875
} catch (HttpClientException $e) {
4976
$this->logError(self::ERROR_CONNECT, $this->getDomainSocketPath(), $e->getCode(), $e->getMessage());
77+
} catch (HttpClientSocketConnectionException $e) {
78+
$this->logError(self::ERROR_CONNECT, $this->getDomainSocketPath(), $e->getCode(), $e->getMessage());
5079
}
5180
}
5281

0 commit comments

Comments
 (0)