From 79b67b3a3056c76f75479abcd00ebe5cbbfc3b6e Mon Sep 17 00:00:00 2001
From: Ere Maijala <ere.maijala@helsinki.fi>
Date: Tue, 3 Sep 2019 15:11:06 +0300
Subject: [PATCH] Alma: Make request timeout configurable and set default to 30
 seconds. (#1418)

---
 config/vufind/Alma.ini                       | 2 ++
 module/VuFind/src/VuFind/ILS/Driver/Alma.php | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/config/vufind/Alma.ini b/config/vufind/Alma.ini
index f5bda3647c7..7c5b26fe8be 100644
--- a/config/vufind/Alma.ini
+++ b/config/vufind/Alma.ini
@@ -3,6 +3,8 @@
 apiBaseUrl = "https://api-eu.hosted.exlibrisgroup.com/almaws/v1"
 ; An API key configured to allow access to Alma:
 apiKey = "your-key-here"
+; Timeout in seconds when making HTTP requests to the Alma APIs:
+http_timeout = 30
 ; Patron login method to use. The following options are available:
 ; vufind    Use VuFind's user database for authentication -- patrons are retrieved
 ;           from Alma without a password (default)
diff --git a/module/VuFind/src/VuFind/ILS/Driver/Alma.php b/module/VuFind/src/VuFind/ILS/Driver/Alma.php
index 6c7ce168989..51df496fdc6 100644
--- a/module/VuFind/src/VuFind/ILS/Driver/Alma.php
+++ b/module/VuFind/src/VuFind/ILS/Driver/Alma.php
@@ -156,6 +156,10 @@ class Alma extends AbstractBase implements \VuFindHttp\HttpServiceAwareInterface
             // Set method
             $client->setMethod($method);
 
+            // Set timeout
+            $timeout = $this->config['Catalog']['http_timeout'] ?? 30;
+            $client->setOptions(['timeout' => $timeout]);
+
             // Set other GET parameters (apikey and other URL parameters are used
             // also with e.g. POST requests)
             $client->setParameterGet($paramsGet);
-- 
GitLab