Skip to content

Commit 74ee8b0

Browse files
balpingJens-G
authored andcommitted
THRIFT-1482: Unix domain socket support under PHP
Client: php Patch: Balázs Dura-Kovács, Volodymyr Panivko This closes #3109 This closes #3130
1 parent b3fc4b2 commit 74ee8b0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/php/lib/Transport/TSocket.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function open()
218218
throw new TTransportException('Cannot open null host', TTransportException::NOT_OPEN);
219219
}
220220

221-
if ($this->port_ <= 0) {
221+
if ($this->port_ <= 0 && strpos($this->host_, 'unix://') !== 0) {
222222
throw new TTransportException('Cannot open without port', TTransportException::NOT_OPEN);
223223
}
224224

lib/php/test/Unit/Lib/Transport/TSocketTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,50 @@ public function testOpenPersist()
246246
$this->assertTrue($transport->isOpen());
247247
}
248248

249+
public function testOpenUnixSocket()
250+
{
251+
$host = 'unix:///tmp/ipc.sock';
252+
$port = -1;
253+
$persist = false;
254+
$debugHandler = null;
255+
$handle = fopen('php://memory', 'r+');
256+
257+
$this->getFunctionMock('Thrift\Transport', 'fsockopen')
258+
->expects($this->once())
259+
->with(
260+
$host,
261+
$port,
262+
$this->anything(), #$errno,
263+
$this->anything(), #$errstr,
264+
$this->anything() #$this->sendTimeoutSec_ + ($this->sendTimeoutUsec_ / 1000000),
265+
)
266+
->willReturn($handle);
267+
268+
$this->getFunctionMock('Thrift\Transport', 'socket_import_stream')
269+
->expects($this->once())
270+
->with($handle)
271+
->willReturn(true);
272+
273+
$this->getFunctionMock('Thrift\Transport', 'socket_set_option')
274+
->expects($this->once())
275+
->with(
276+
$this->anything(), #$socket,
277+
SOL_TCP, #$level
278+
TCP_NODELAY, #$option
279+
1 #$value
280+
)
281+
->willReturn(true);
282+
283+
$transport = new TSocket(
284+
$host,
285+
$port,
286+
$persist,
287+
$debugHandler
288+
);
289+
290+
$transport->open();
291+
}
292+
249293
/**
250294
* @dataProvider open_THRIFT_5132_DataProvider
251295
*/

0 commit comments

Comments
 (0)