File indexing completed on 2024-06-23 05:55:43

0001 <?php
0002 
0003 /**
0004  * Copyright (c) 2007-2011, Servigistics, Inc.
0005  * All rights reserved.
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions are met:
0009  *
0010  *  - Redistributions of source code must retain the above copyright notice,
0011  *    this list of conditions and the following disclaimer.
0012  *  - Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *  - Neither the name of Servigistics, Inc. nor the names of
0016  *    its contributors may be used to endorse or promote products derived from
0017  *    this software without specific prior written permission.
0018  *
0019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0029  * POSSIBILITY OF SUCH DAMAGE.
0030  *
0031  * @copyright Copyright 2007-2011 Servigistics, Inc. (http://servigistics.com)
0032  * @license http://solr-php-client.googlecode.com/svn/trunk/COPYING New BSD
0033  * @version $Id: $
0034  *
0035  * @package Apache
0036  * @subpackage Solr
0037  * @author Timo Schmidt <timo.schmidt@aoemedia.de>, Donovan Jimenez <djimenez@conduit-it.com>
0038  */
0039 
0040 /**
0041  * Convenience class that implements the transport implementation. Can be extended by
0042  * real implementations to do some of the common book keeping
0043  */
0044 abstract class Zend_Service_Solr_HttpTransport_Abstract implements Zend_Service_Solr_HttpTransport_Interface {
0045 
0046     /**
0047      * Our default timeout value for requests that don't specify a timeout
0048      *
0049      * @var float
0050      */
0051     private $_defaultTimeout = false;
0052 
0053     /**
0054      * Get the current default timeout setting (initially the default_socket_timeout ini setting)
0055      * in seconds
0056      *
0057      * @return float
0058      */
0059     public function getDefaultTimeout() {
0060         // lazy load the default timeout from the ini settings
0061         if ($this->_defaultTimeout === false) {
0062             $this->_defaultTimeout = (int) ini_get('default_socket_timeout');
0063 
0064             // double check we didn't get 0 for a timeout
0065             if ($this->_defaultTimeout <= 0) {
0066                 $this->_defaultTimeout = 60;
0067             }
0068         }
0069 
0070         return $this->_defaultTimeout;
0071     }
0072 
0073     /**
0074      * Set the current default timeout for all HTTP requests
0075      *
0076      * @param float $timeout
0077      */
0078     public function setDefaultTimeout($timeout) {
0079         $timeout = (float) $timeout;
0080 
0081         if ($timeout >= 0) {
0082             $this->_defaultTimeout = $timeout;
0083         }
0084     }
0085 
0086 }