From dc7c81a4a6888f93d1c0612d1cdc258873569ab4 Mon Sep 17 00:00:00 2001 From: Sorin Date: Thu, 25 Jan 2024 10:55:54 +0200 Subject: [PATCH] request timeout as a separate config param --- src/SuperPREDTargetPrediction.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/SuperPREDTargetPrediction.php b/src/SuperPREDTargetPrediction.php index 92b873f..055f1eb 100644 --- a/src/SuperPREDTargetPrediction.php +++ b/src/SuperPREDTargetPrediction.php @@ -25,9 +25,12 @@ class SuperPREDTargetPrediction private string $userAgent = ''; private string $SMILES_code = ''; - public function __construct() + private int $requestTimeout; + + public function __construct(int $requestTimeout = 20) { - $this->userAgent = $this->userAgentsPool[rand(0, count($this->userAgentsPool) - 1)]; + $this->requestTimeout = $requestTimeout; + $this->userAgent = $this->userAgentsPool[rand(0, count($this->userAgentsPool) - 1)]; } public function setUserAgent(string $ua): SuperPREDTargetPrediction @@ -131,7 +134,7 @@ public function getRawTargets(): array private function doPostCall(string $url, array $post_data): ResponseInterface { $client = new Client([ - 'timeout' => 20, + 'timeout' => $this->requestTimeout, ]); return $client->request('POST', $url, [