Skip to content

Commit a0cdfde

Browse files
committed
added an timeout for OAuth2-Provider
1 parent 07a4cd5 commit a0cdfde

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Restado.php

+12
Original file line numberDiff line numberDiff line change
@@ -939,12 +939,24 @@ public function getEnergySavingsReport($access_token, $year, $month, $country_co
939939
* @return GenericProvider
940940
*/
941941
private function getProvider() {
942+
943+
if (config('tado.timeout') !== NULL) {
944+
$timeout = config('tado.timeout');
945+
} else {
946+
// set a timeout based on PHP max_execution_time if not configured
947+
// in case of an invalid max_execution_time (empty or FALSE) a default of 20s is being set
948+
// in case of an valid max_execution_time the timeout is being set to 90% of this value with a maximum of 20s
949+
$timeout = floor((int)ini_get('max_execution_time') * 0.9);
950+
if (($timeout>20) or ($timeout<=0)) $timeout = 20;
951+
}
952+
942953
return new GenericProvider([
943954
'clientId' => config('tado.clientId'), // The client ID assigned to you by the provider
944955
'clientSecret' => config('tado.clientSecret'), // The client password assigned to you by the provider
945956
'urlAuthorize' => 'https://auth.tado.com/oauth/authorize',
946957
'urlAccessToken' => 'https://auth.tado.com/oauth/token',
947958
'urlResourceOwnerDetails' => null,
959+
'timeout' => $timeout,
948960
]);
949961
}
950962
}

0 commit comments

Comments
 (0)