Sekunden ab, bei Y verlängert sich die Session mit jeder Benutzung private $CredentialToken = false; private $kas_flood_delay = 2; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->login(); } public function action($func, $para = array()){ $this->checkSession($func); try { $Params = array(); // Parameter für die API-Funktion $SoapRequest = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasApi.wsdl'); $req = $SoapRequest->KasApi(json_encode(array( 'KasUser' => $this->kas_user, // KAS-User 'KasAuthType' => 'session', // Auth per Sessiontoken 'KasAuthData' => $this->CredentialToken, // Auth-Token 'KasRequestType' => $func, // API-Funktion 'KasRequestParams' => $para // Parameter an die API-Funktion ))); Session::put('flood_protection.'.$func, time() + $this->kas_flood_delay + 0.2); if(isset($req['Response']['ReturnString']) && $req['Response']['ReturnString'] == "TRUE"){ return $req['Response']['ReturnInfo']; } return $req; } // Fehler abfangen und ausgeben catch (SoapFault $fault) { trigger_error(" Fehlernummer: {$fault->faultcode}, Fehlermeldung: {$fault->faultstring}, Verursacher: {$fault->faultactor}, Details: {$fault->detail}", E_USER_ERROR); } } private function login(){ $this->checkSession('auth'); try { $SoapLogon = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl'); $this->CredentialToken = $SoapLogon->KasAuth(json_encode(array( 'KasUser' => $this->kas_user, 'KasAuthType' => 'sha1', 'KasPassword' => sha1($this->kas_pass), 'SessionLifeTime' => $this->session_lifetime, 'SessionUpdateLifeTime' => $this->session_update_lifetime ))); Session::put('flood_protection.auth', time() + $this->kas_flood_delay + 0.2); } // Fehler abfangen und ausgeben catch (SoapFault $fault) { trigger_error("Fehlernummer: {$fault->faultcode}, Fehlermeldung: {$fault->faultstring}, Verursacher: {$fault->faultactor}, Details: {$fault->detail}", E_USER_ERROR); } } private function checkSession($func) { $name = 'flood_protection.'.$func; if(Session::exists($name)){ $time_to_wait = (float)Session::get($name) - time(); Session::forget($name); }else { $time_to_wait = 0; } if ( $time_to_wait >= 0 ) { usleep( intval( $time_to_wait*1000000 ) ); } } }