/**
  * Constructor method
  *
  * @param string $wsdl
  * @param string $username
  * @param string $userpass
  * @param bool $dryrun
  * @throws PlentymarketsSoapConnectionException
  * @return PlentymarketsSoapClient
  */
 protected function __construct($wsdl, $username, $userpass, $dryrun = false)
 {
     // Set the connection timeout
     if (function_exists('ini_set')) {
         ini_set('default_socket_timeout', 60);
     }
     // Get the config
     $this->Config = PlentymarketsConfig::getInstance();
     //
     $this->wsdl = $wsdl;
     $this->username = $username;
     $this->userpass = $userpass;
     $this->dryrun = (bool) $dryrun;
     // Options
     $options = array();
     $options['features'] = SOAP_SINGLE_ELEMENT_ARRAYS;
     $options['version'] = SOAP_1_2;
     $options['encoding'] = 'utf-8';
     $options['exceptions'] = true;
     $options['trace'] = true;
     $options['connection_timeout'] = 10;
     // PHP 5.4
     // $options['keep_alive'] = false;
     // Cache
     if ($_SERVER['SERVER_ADDR'] != '127.0.0.1') {
         $options['cache_wsdl'] = WSDL_CACHE_NONE;
     }
     // Compression
     if ($this->Config->getApiUseGzipCompression(false)) {
         $options['compression'] = SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP;
     }
     // HTTP 1.0 to send "Connection: close"
     $context = stream_context_create(array('http' => array('protocol_version' => 1.0)));
     $options['stream_context'] = $context;
     // Init the client
     $retries = 0;
     do {
         try {
             @parent::__construct($wsdl, $options);
             break;
         } catch (SoapFault $E) {
             ++$retries;
             if ($retries == 3) {
                 throw new PlentymarketsSoapConnectionException();
             }
             sleep($retries * self::NUMBER_OF_SECONDS_SLEEP_CONNECTION);
         }
     } while ($retries < self::NUMBER_OF_RETRIES_MAX);
     // Check whether auth cache exist and whether the file is from today
     if (!$dryrun && date('Y-m-d', $this->Config->getApiLastAuthTimestamp(0)) == date('Y-m-d')) {
         // Get auth data from the config
         $this->userId = $this->Config->getApiUserID('');
         $this->userToken = $this->Config->getApiToken('');
     } else {
         // Get a new token
         $this->getToken();
     }
     // Set the new token
     $this->setSoapHeaders();
 }