From 8d8615137195bd1afe8e5a190e64d7a7f5550345 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Tue, 8 Jul 2014 13:40:49 -0400 Subject: [PATCH] Configurable Syndetics timeout. --- config/vufind/config.ini | 2 ++ .../src/VuFind/Content/AbstractSyndetics.php | 26 ++++++++++++++++++- .../VuFind/Content/AuthorNotes/Factory.php | 3 ++- .../src/VuFind/Content/Excerpts/Factory.php | 3 ++- .../src/VuFind/Content/Reviews/Factory.php | 3 ++- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/config/vufind/config.ini b/config/vufind/config.ini index f067db36464..6e172c934ae 100644 --- a/config/vufind/config.ini +++ b/config/vufind/config.ini @@ -591,6 +591,8 @@ authors = Wikipedia use_ssl = false plus = false ;plus_id = "MySyndeticsId" +; timeout value (in seconds) for API calls: +timeout = 10 ; Booksite CATS Enhanced Content - cover images, reviews, description, etc. [Booksite] diff --git a/module/VuFind/src/VuFind/Content/AbstractSyndetics.php b/module/VuFind/src/VuFind/Content/AbstractSyndetics.php index acfd53f23f3..8ba8431c1fa 100644 --- a/module/VuFind/src/VuFind/Content/AbstractSyndetics.php +++ b/module/VuFind/src/VuFind/Content/AbstractSyndetics.php @@ -53,16 +53,40 @@ abstract class AbstractSyndetics extends AbstractBase */ protected $usePlus; + /** + * HTTP timeout for API calls (in seconds) + * + * @var int + */ + protected $timeout; + /** * Constructor * * @param bool $useSSL Use SSL URLs? * @param bool $usePlus Use Syndetics Plus? + * @param int $timeout HTTP timeout for API calls (in seconds) */ - public function __construct($useSSL = false, $usePlus = false) + public function __construct($useSSL = false, $usePlus = false, $timeout = 10) { $this->useSSL = $useSSL; $this->usePlus = $usePlus; + $this->timeout = $timeout; + } + + /** + * Get an HTTP client + * + * @param string $url URL for client to use + * + * @return \Zend\Http\Client + * @throws \Exception + */ + protected function getHttpClient($url) + { + $client = parent::getHttpClient($url); + $client->setOptions(array('timeout' => $this->timeout)); + return $client; } /** diff --git a/module/VuFind/src/VuFind/Content/AuthorNotes/Factory.php b/module/VuFind/src/VuFind/Content/AuthorNotes/Factory.php index b41e185b0a1..4b61bba1ec6 100644 --- a/module/VuFind/src/VuFind/Content/AuthorNotes/Factory.php +++ b/module/VuFind/src/VuFind/Content/AuthorNotes/Factory.php @@ -52,7 +52,8 @@ class Factory $config = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); return new Syndetics( isset($config->Syndetics->use_ssl) && $config->Syndetics->use_ssl, - $plus + $plus, + isset($config->Syndetics->timeout) ? $config->Syndetics->timeout : 10 ); } diff --git a/module/VuFind/src/VuFind/Content/Excerpts/Factory.php b/module/VuFind/src/VuFind/Content/Excerpts/Factory.php index 2334641c3ea..96155ceb630 100644 --- a/module/VuFind/src/VuFind/Content/Excerpts/Factory.php +++ b/module/VuFind/src/VuFind/Content/Excerpts/Factory.php @@ -52,7 +52,8 @@ class Factory $config = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); return new Syndetics( isset($config->Syndetics->use_ssl) && $config->Syndetics->use_ssl, - $plus + $plus, + isset($config->Syndetics->timeout) ? $config->Syndetics->timeout : 10 ); } diff --git a/module/VuFind/src/VuFind/Content/Reviews/Factory.php b/module/VuFind/src/VuFind/Content/Reviews/Factory.php index 72c0714235e..ac155abdc7e 100644 --- a/module/VuFind/src/VuFind/Content/Reviews/Factory.php +++ b/module/VuFind/src/VuFind/Content/Reviews/Factory.php @@ -52,7 +52,8 @@ class Factory $config = $sm->getServiceLocator()->get('VuFind\Config')->get('config'); return new Syndetics( isset($config->Syndetics->use_ssl) && $config->Syndetics->use_ssl, - $plus + $plus, + isset($config->Syndetics->timeout) ? $config->Syndetics->timeout : 10 ); } -- GitLab