Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions hphp/system/php/redis/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -1568,9 +1568,7 @@ protected function doConnect($host,
$persistent_id,
$retry_interval,
$persistent = false) {
if (!empty($persistent_id)) {
throw new RedisException("Named persistent connections not supported");
}


if ($port <= 0) {
if ((strlen($host) > 0) && ($host[0] == '/')) {
Expand All @@ -1587,16 +1585,25 @@ protected function doConnect($host,
}

if ($persistent) {
$conn = pfsockopen($host, $port, $errno, $errstr, $timeout);
if (!empty($persistent_id)) {
$pid = array('id' => array('persistent_id' => $persistent_id));
$context = stream_context_create($pid);
$sok = $host . ':' . $port;
$conn = stream_socket_client(
$sok, $errno, $errstr, $timeout, 2, $context);
} else {
$conn = pfsockopen($host, $port, $errno, $errstr, $timeout);
}
} else {
$conn = fsockopen($host, $port, $errno, $errstr, $timeout);
$conn = fsockopen($host, $port, $errno, $errstr, $timeout);
}
$this->last_connect = time();
$this->host = $host;
$this->port = $port;
$this->retry_interval = $retry_interval;
$this->timeout_connect = $timeout;
$this->persistent = $persistent;
$this->persistent_id = $persistent_id;
$this->connection = $conn;
$this->dbNumber = 0;
$this->commands = [];
Expand Down
22 changes: 22 additions & 0 deletions hphp/test/slow/ext_redis/pconnectWithoutPID.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
define('REDIS_HOST', getenv('REDIS_TEST_HOST'));
define('REDIS_PORT', getenv('REDIS_TEST_PORT')
? (int)getenv('REDIS_TEST_PORT')
: Redis::DEFAULT_PORT);
define('REDIS_PASS',getenv('REDIS_TEST_PASS')!==null
? getenv('REDIS_TEST_PASS')
: null);

function NewRedisTestInstance() {
$expecting = array(
'timeout' => 0
);
$r = new Redis();
$conn = $r->pconnect(REDIS_HOST, REDIS_PORT, $expecting['timeout']);
var_dump($conn);
$authok = REDIS_PASS ? $r->auth(REDIS_PASS) : true;
var_dump($authok);
return $r;
}
$r = NewRedisTestInstance();
if ($r) echo true;
3 changes: 3 additions & 0 deletions hphp/test/slow/ext_redis/pconnectWithoutPID.php.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bool(true)
bool(true)
1
12 changes: 12 additions & 0 deletions hphp/test/slow/ext_redis/pconnectWithoutPID.php.skipif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

if (!getenv('REDIS_TEST_HOST')) {
echo 'skip';
} else {
// Some people might have this variable set, but don't have the server running
$output = array();
exec("redis-cli ping", $output);
if ($output[0] !== "PONG") {
echo 'skip';
}
}
26 changes: 26 additions & 0 deletions hphp/test/slow/ext_redis/withpersistandid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
define('REDIS_HOST', getenv('REDIS_TEST_HOST'));
define('REDIS_PORT', getenv('REDIS_TEST_PORT')
? (int)getenv('REDIS_TEST_PORT')
: Redis::DEFAULT_PORT);
define('REDIS_PASS', getenv('REDIS_TEST_PASS') !== null
? getenv('REDIS_TEST_PASS')
: null);

function NewRedisTestInstance() {
$expecting = array(
'timeout' => 0,
'database' => 0
);
$r = new Redis();
$persistentId = REDIS_PORT . $expecting['timeout'] . $expecting['database'];
$conn = $r->pconnect(
REDIS_HOST, REDIS_PORT, $expecting['timeout'], $persistentId);
var_dump($conn);
$authok = REDIS_PASS ? $r->auth(REDIS_PASS) : true;
var_dump($authok);
return $r;
}

$r = NewRedisTestInstance();
if ($r) echo true;
3 changes: 3 additions & 0 deletions hphp/test/slow/ext_redis/withpersistandid.php.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bool(true)
bool(true)
1
12 changes: 12 additions & 0 deletions hphp/test/slow/ext_redis/withpersistandid.php.skipif
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

if (!getenv('REDIS_TEST_HOST')) {
echo 'skip';
} else {
// Some people might have this variable set, but don't have the server running
$output = array();
exec("redis-cli ping", $output);
if ($output[0] !== "PONG") {
echo 'skip';
}
}