Index: branches/REL1_4/phase3/includes/memcached-client.php |
— | — | @@ -205,6 +205,22 @@ |
206 | 206 | */ |
207 | 207 | var $_active; |
208 | 208 | |
| 209 | + /** |
| 210 | + * Stream timeout in seconds. Applies for example to fread() |
| 211 | + * |
| 212 | + * @var integer |
| 213 | + * @access private |
| 214 | + */ |
| 215 | + var $_timeout_seconds; |
| 216 | + |
| 217 | + /** |
| 218 | + * Stream timeout in microseconds |
| 219 | + * |
| 220 | + * @var integer |
| 221 | + * @access private |
| 222 | + */ |
| 223 | + var $_timeout_microseconds; |
| 224 | + |
209 | 225 | // }}} |
210 | 226 | // }}} |
211 | 227 | // {{{ methods |
— | — | @@ -231,6 +247,9 @@ |
232 | 248 | |
233 | 249 | $this->_cache_sock = array(); |
234 | 250 | $this->_host_dead = array(); |
| 251 | + |
| 252 | + $this->_timeout_seconds = 1; |
| 253 | + $this->_timeout_microseconds = 0; |
235 | 254 | } |
236 | 255 | |
237 | 256 | // }}} |
— | — | @@ -606,6 +625,20 @@ |
607 | 626 | $this->_single_sock = $this->_servers[0]; |
608 | 627 | } |
609 | 628 | |
| 629 | + /** |
| 630 | + * Sets the timeout for new connections |
| 631 | + * |
| 632 | + * @param integer $seconds Number of seconds |
| 633 | + * @param integer $microseconds Number of microseconds |
| 634 | + * |
| 635 | + * @access public |
| 636 | + */ |
| 637 | + function set_timeout ($seconds, $microseconds) |
| 638 | + { |
| 639 | + $this->_timeout_seconds = $seconds; |
| 640 | + $this->_timeout_microseconds = $microseconds; |
| 641 | + } |
| 642 | + |
610 | 643 | // }}} |
611 | 644 | // }}} |
612 | 645 | // {{{ private methods |
— | — | @@ -654,6 +687,10 @@ |
655 | 688 | $this->_debugprint( "Error connecting to $host: $errstr\n" ); |
656 | 689 | return false; |
657 | 690 | } |
| 691 | + |
| 692 | + // Initialise timeout |
| 693 | + stream_set_timeout($sock, $this->_timeout_seconds, $this->_timeout_microseconds); |
| 694 | + |
658 | 695 | return true; |
659 | 696 | } |
660 | 697 | |