From 1c18aa67abaf179602458909e50d983a44ee2dc7 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 18 Apr 2018 12:03:52 +0200 Subject: [locationinfo] davinchi: Reuse curl handle --- .../coursebackend/coursebackend_davinci.inc.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php index 8843e372..ed3d7ec2 100644 --- a/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php +++ b/modules-available/locationinfo/inc/coursebackend/coursebackend_davinci.inc.php @@ -6,6 +6,10 @@ class CourseBackend_Davinci extends CourseBackend private $location; private $verifyHostname = true; private $verifyCert = true; + /** + * @var bool|resource + */ + private $curlHandle = false; public function setCredentialsInternal($data) { @@ -69,7 +73,9 @@ class CourseBackend_Davinci extends CourseBackend { $url = $this->location . "content=xml&type=room&name=" . urlencode($roomId) . "&startdate=" . $startDate->format('d.m.Y') . "&enddate=" . $endDate->format('d.m.Y'); - $ch = curl_init(); + if ($this->curlHandle === false) { + $this->curlHandle = curl_init(); + } $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, @@ -78,16 +84,15 @@ class CourseBackend_Davinci extends CourseBackend CURLOPT_URL => $url, ); - curl_setopt_array($ch, $options); - $output = curl_exec($ch); + curl_setopt_array($this->curlHandle, $options); + $output = curl_exec($this->curlHandle); if ($output === false) { - $this->error = 'Curl error: ' . curl_error($ch); + $this->error = 'Curl error: ' . curl_error($this->curlHandle); return false; } else { $this->error = false; ///Operation completed successfully } - curl_close($ch); return $output; } @@ -142,4 +147,11 @@ class CourseBackend_Davinci extends CourseBackend } return $schedules; } + + public function __destruct() + { + if ($this->curlHandle !== false) { + curl_close($this->curlHandle); + } + } } -- cgit v1.2.3-55-g7522