Skip to content

Commit dbf4e5f

Browse files
committed
update to 0.15.0
1 parent e3dbcfb commit dbf4e5f

File tree

4 files changed

+57
-29
lines changed

4 files changed

+57
-29
lines changed

src/ClassLoader/ThriftClassLoader.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@ class ThriftClassLoader
4040
protected $definitions = array();
4141

4242
/**
43-
* Do we use APC cache ?
43+
* Do we use APCu cache ?
4444
* @var boolean
4545
*/
46-
protected $apc = false;
46+
protected $apcu = false;
4747

4848
/**
49-
* APC Cache prefix
49+
* APCu Cache prefix
5050
* @var string
5151
*/
52-
protected $apc_prefix;
52+
protected $apcu_prefix;
5353

5454
/**
55-
* Set autoloader to use APC cache
55+
* Set autoloader to use APCu cache
5656
* @param boolean $apc
57-
* @param string $apc_prefix
57+
* @param string $apcu_prefix
5858
*/
59-
public function __construct($apc = false, $apc_prefix = null)
59+
public function __construct($apc = false, $apcu_prefix = null)
6060
{
61-
$this->apc = $apc;
62-
$this->apc_prefix = $apc_prefix;
61+
$this->apcu = $apc;
62+
$this->apcu_prefix = $apcu_prefix;
6363
}
6464

6565
/**
@@ -101,22 +101,22 @@ public function register($prepend = false)
101101
*/
102102
public function loadClass($class)
103103
{
104-
if ((true === $this->apc && ($file = $this->findFileInApc($class))) or
104+
if ((true === $this->apcu && ($file = $this->findFileInApcu($class))) or
105105
($file = $this->findFile($class))
106106
) {
107107
require_once $file;
108108
}
109109
}
110110

111111
/**
112-
* Loads the given class or interface in APC.
112+
* Loads the given class or interface in APCu.
113113
* @param string $class The name of the class
114114
* @return string
115115
*/
116-
protected function findFileInApc($class)
116+
protected function findFileInApcu($class)
117117
{
118-
if (false === $file = apc_fetch($this->apc_prefix . $class)) {
119-
apc_store($this->apc_prefix . $class, $file = $this->findFile($class));
118+
if (false === $file = apcu_fetch($this->apcu_prefix . $class)) {
119+
apcu_store($this->apcu_prefix . $class, $file = $this->findFile($class));
120120
}
121121

122122
return $file;

src/Transport/TCurlClient.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ class TCurlClient extends TTransport
8383
*/
8484
protected $timeout_;
8585

86+
/**
87+
* Connection timeout
88+
*
89+
* @var float
90+
*/
91+
protected $connectionTimeout_;
92+
8693
/**
8794
* http headers
8895
*
@@ -109,6 +116,7 @@ public function __construct($host, $port = 80, $uri = '', $scheme = 'http')
109116
$this->request_ = '';
110117
$this->response_ = null;
111118
$this->timeout_ = null;
119+
$this->connectionTimeout_ = null;
112120
$this->headers_ = array();
113121
}
114122

@@ -122,6 +130,16 @@ public function setTimeoutSecs($timeout)
122130
$this->timeout_ = $timeout;
123131
}
124132

133+
/**
134+
* Set connection timeout
135+
*
136+
* @param float $connectionTimeout
137+
*/
138+
public function setConnectionTimeoutSecs($connectionTimeout)
139+
{
140+
$this->connectionTimeout_ = $connectionTimeout;
141+
}
142+
125143
/**
126144
* Whether this transport is open.
127145
*
@@ -237,6 +255,14 @@ public function flush()
237255
curl_setopt(self::$curlHandle, CURLOPT_TIMEOUT, $this->timeout_);
238256
}
239257
}
258+
if ($this->connectionTimeout_ > 0) {
259+
if ($this->connectionTimeout_ < 1.0) {
260+
// Timestamps smaller than 1 second are ignored when CURLOPT_CONNECTTIMEOUT is used
261+
curl_setopt(self::$curlHandle, CURLOPT_CONNECTTIMEOUT_MS, 1000 * $this->connectionTimeout_);
262+
} else {
263+
curl_setopt(self::$curlHandle, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout_);
264+
}
265+
}
240266
curl_setopt(self::$curlHandle, CURLOPT_POSTFIELDS, $this->request_);
241267
$this->request_ = '';
242268

src/Transport/TSocket.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@ public function open()
251251
}
252252

253253
if (function_exists('socket_import_stream') && function_exists('socket_set_option')) {
254-
$socket = socket_import_stream($this->handle_);
255-
socket_set_option($socket, SOL_TCP, TCP_NODELAY, 1);
254+
// warnings silenced due to bug https://bugs.php.net/bug.php?id=70939
255+
$socket = @socket_import_stream($this->handle_);
256+
@socket_set_option($socket, SOL_TCP, TCP_NODELAY, 1);
256257
}
257258
}
258259

@@ -328,7 +329,8 @@ public function write($buf)
328329
if ($writable > 0) {
329330
// write buffer to stream
330331
$written = fwrite($this->handle_, $buf);
331-
if ($written === -1 || $written === false) {
332+
$closed_socket = $written === 0 && feof($this->handle_);
333+
if ($written === -1 || $written === false || $closed_socket) {
332334
throw new TTransportException(
333335
'TSocket: Could not write ' . TStringFuncFactory::create()->strlen($buf) . ' bytes ' .
334336
$this->host_ . ':' . $this->port_

src/Transport/TSocketPool.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
use Thrift\Exception\TException;
2626

2727
/**
28-
* This library makes use of APC cache to make hosts as down in a web
29-
* environment. If you are running from the CLI or on a system without APC
28+
* This library makes use of APCu cache to make hosts as down in a web
29+
* environment. If you are running from the CLI or on a system without APCu
3030
* installed, then these null functions will step in and act like cache
3131
* misses.
3232
*/
33-
if (!function_exists('apc_fetch')) {
34-
function apc_fetch($key)
33+
if (!function_exists('apcu_fetch')) {
34+
function apcu_fetch($key)
3535
{
3636
return false;
3737
}
3838

39-
function apc_store($key, $var, $ttl = 0)
39+
function apcu_store($key, $var, $ttl = 0)
4040
{
4141
return false;
4242
}
@@ -202,11 +202,11 @@ public function open()
202202
// This extracts the $host and $port variables
203203
extract($this->servers_[$i]);
204204

205-
// Check APC cache for a record of this server being down
205+
// Check APCu cache for a record of this server being down
206206
$failtimeKey = 'thrift_failtime:' . $host . ':' . $port . '~';
207207

208208
// Cache miss? Assume it's OK
209-
$lastFailtime = apc_fetch($failtimeKey);
209+
$lastFailtime = apcu_fetch($failtimeKey);
210210
if ($lastFailtime === false) {
211211
$lastFailtime = 0;
212212
}
@@ -251,7 +251,7 @@ public function open()
251251

252252
// Only clear the failure counts if required to do so
253253
if ($lastFailtime > 0) {
254-
apc_store($failtimeKey, 0);
254+
apcu_store($failtimeKey, 0);
255255
}
256256

257257
// Successful connection, return now
@@ -265,7 +265,7 @@ public function open()
265265
$consecfailsKey = 'thrift_consecfails:' . $host . ':' . $port . '~';
266266

267267
// Ignore cache misses
268-
$consecfails = apc_fetch($consecfailsKey);
268+
$consecfails = apcu_fetch($consecfailsKey);
269269
if ($consecfails === false) {
270270
$consecfails = 0;
271271
}
@@ -284,12 +284,12 @@ public function open()
284284
);
285285
}
286286
// Store the failure time
287-
apc_store($failtimeKey, time());
287+
apcu_store($failtimeKey, time());
288288

289289
// Clear the count of consecutive failures
290-
apc_store($consecfailsKey, 0);
290+
apcu_store($consecfailsKey, 0);
291291
} else {
292-
apc_store($consecfailsKey, $consecfails);
292+
apcu_store($consecfailsKey, $consecfails);
293293
}
294294
}
295295
}

0 commit comments

Comments
 (0)