From 8ef451390988407ce8b1d0777f77e9811da5d666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@users.noreply.github.com> Date: Wed, 14 Sep 2016 14:14:20 +0200 Subject: [PATCH] Added timeout settings to DAIA and PAIA drivers (#793) --- config/vufind/DAIA.ini | 5 +++++ config/vufind/PAIA.ini | 5 +++++ module/VuFind/src/VuFind/ILS/Driver/DAIA.php | 13 ++++++++++++- module/VuFind/src/VuFind/ILS/Driver/PAIA.php | 16 ++++++++++++++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/config/vufind/DAIA.ini b/config/vufind/DAIA.ini index 2986e6b32ea..97b0cfe2e0c 100644 --- a/config/vufind/DAIA.ini +++ b/config/vufind/DAIA.ini @@ -24,6 +24,11 @@ ; The base URL for the DAIA webservice. baseUrl = [your DAIA server base url] +; Set a DAIA specific timeout in seconds to be used for DAIA http requests (defaults +; to Zend defaults or as defined in +; vendor/vufind-org/vufindhttp/src/VuFindHttp/HttpService.php) +;timeout = 30 + ; The prefix prepended to the VuFind record Id resulting in the document URI ; used for the DAIA request (default = ppn:) (the prefix usually defines the ; field which the DAIA server uses for the loookup - e.g. ppn: or isbn:). diff --git a/config/vufind/PAIA.ini b/config/vufind/PAIA.ini index dd7ade3a47e..38f6e661c4d 100644 --- a/config/vufind/PAIA.ini +++ b/config/vufind/PAIA.ini @@ -9,6 +9,11 @@ ; base URL of the PAIA server WITH trailing slash baseUrl = "" +; Set a PAIA specific timeout in seconds to be used for PAIA http requests (defaults +; to Zend defaults or as defined in +; vendor/vufind-org/vufindhttp/src/VuFindHttp/HttpService.php) +;timeout = 30 + ; Enable caching for PAIA items (default is false). TTL for cached data will be the ; same as for DAIA cache (see cacheLifetime setting in DAIA.ini). ;paiaCache = false diff --git a/module/VuFind/src/VuFind/ILS/Driver/DAIA.php b/module/VuFind/src/VuFind/ILS/Driver/DAIA.php index 2395dbc0dac..3d08827771f 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/DAIA.php +++ b/module/VuFind/src/VuFind/ILS/Driver/DAIA.php @@ -59,6 +59,13 @@ class DAIA extends AbstractBase implements */ protected $baseUrl; + /** + * Timeout in seconds to be used for DAIA http requests + * + * @var string + */ + protected $daiaTimeout = null; + /** * Flag to switch on/off caching for DAIA items * @@ -142,6 +149,10 @@ class DAIA extends AbstractBase implements } else { throw new ILSException('DAIA/baseUrl configuration needs to be set.'); } + // use DAIA specific timeout setting for http requests if configured + if ((isset($this->config['DAIA']['timeout']))) { + $this->daiaTimeout = $this->config['DAIA']['timeout']; + } if (isset($this->config['DAIA']['daiaResponseFormat'])) { $this->daiaResponseFormat = strtolower( $this->config['DAIA']['daiaResponseFormat'] @@ -448,7 +459,7 @@ class DAIA extends AbstractBase implements try { $result = $this->httpService->get( $this->baseUrl, - $params, null, $http_headers + $params, $this->daiaTimeout, $http_headers ); } catch (\Exception $e) { throw new ILSException( diff --git a/module/VuFind/src/VuFind/ILS/Driver/PAIA.php b/module/VuFind/src/VuFind/ILS/Driver/PAIA.php index df079cbaaee..9129e7270b0 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/PAIA.php +++ b/module/VuFind/src/VuFind/ILS/Driver/PAIA.php @@ -56,6 +56,13 @@ class PAIA extends DAIA */ protected $paiaURL; + /** + * Timeout in seconds to be used for PAIA http requests + * + * @var + */ + protected $paiaTimeout = null; + /** * Flag to switch on/off caching for PAIA items * @@ -164,6 +171,11 @@ class PAIA extends DAIA } $this->paiaURL = $this->config['PAIA']['baseUrl']; + // use PAIA specific timeout setting for http requests if configured + if ((isset($this->config['PAIA']['timeout']))) { + $this->paiaTimeout = $this->config['PAIA']['timeout']; + } + // do we have caching enabled for PAIA if (isset($this->config['PAIA']['paiaCache'])) { $this->paiaCacheEnabled = $this->config['PAIA']['paiaCache']; @@ -1502,7 +1514,7 @@ class PAIA extends DAIA $this->paiaURL . $file, $postData, 'application/json; charset=UTF-8', - null, + $this->paiaTimeout, $http_headers ); } catch (\Exception $e) { @@ -1539,7 +1551,7 @@ class PAIA extends DAIA try { $result = $this->httpService->get( $this->paiaURL . $file, - [], null, $http_headers + [], $this->paiaTimeout, $http_headers ); } catch (\Exception $e) { throw new ILSException($e->getMessage()); -- GitLab