New: Add global parameter connect timeout and response timeout for all external access.

This commit is contained in:
Laurent Destailleur 2011-04-03 18:02:18 +00:00
parent 7b4c7f98f7
commit ae89c2175b
5 changed files with 55 additions and 7 deletions

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 20011 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -823,7 +823,7 @@ MAIN_DISABLE_METEO=Disable meteo view
TestLoginToAPI=Test login to API
ProxyDesc=Some features of Dolibarr need to have an Internet access to work. Define here parameters for this. If the Dolibarr server is behind a Proxy server, those parameters tells Dolibarr how to access Internet through it.
ExternalAccess=External access
MAIN_PROXY_USE=Use a proxy server
MAIN_PROXY_USE=Use a proxy server (otherwise direct access to internet)
MAIN_PROXY_HOST=Name/Address of proxy server
MAIN_PROXY_PORT=Port of proxy server
MAIN_PROXY_USER=Login to use the proxy server

View File

@ -834,7 +834,7 @@ MAIN_DISABLE_METEO=Désactiver la vue météo
TestLoginToAPI=Tester connexion à l'API
ProxyDesc=Certaines fonctions de Dolibarr nécessitent que le serveur ait accès à internet. Définissez ici les paramètres de ces accès. Si le serveur Dolibarr est derrière un proxy, ces paramètres indiquent à Dolibarr comment le traverser.
ExternalAccess=Accès externes
MAIN_PROXY_USE=Utiliser un serveur proxy mandataire
MAIN_PROXY_USE=Utiliser un serveur proxy mandataire (sinon accès direct à internet)
MAIN_PROXY_HOST=Nom/Adresse du serveur proxy mandataire
MAIN_PROXY_PORT=Port du serveur proxy mandataire
MAIN_PROXY_USER=Login pour passer le serveur proxy mandataire

View File

@ -430,10 +430,10 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m
if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; }
elseif (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; }
if (dol_strlen($reg[$posy]) < 2) return 'ErrorCantUseRazWithYearOnOneDigit';
}
}
else
{
if (! preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode)) return 'ErrorCantUseRazIfNoYearInMask';
if (! preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode)) return 'ErrorCantUseRazIfNoYearInMask';
if (preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=0; }
}
//print "x".$maskwithonlyymcode." ".$maskraz." ".$posy." ".$posm;
@ -1113,4 +1113,48 @@ function dol_buildlogin($lastname,$firstname)
$login.=strtolower(dol_string_unaccent($lastname));
$login=dol_string_nospecial($login,''); // For special names
return $login;
}
}
/**
* Return array to use for SoapClient constructor
* @return param
*/
function getSoapParams()
{
global $conf;
$params=array();
$proxyuse=($conf->global->MAIN_PROXY_USE?true:false);
$proxyhost=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_HOST:false);
$proxyport=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_PORT:false);
$proxyuser=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_USER:false);
$proxypass=($conf->global->MAIN_PROXY_USE?$conf->global->MAIN_PROXY_PASS:false);
$timeout=(empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?10:$conf->global->MAIN_USE_CONNECT_TIMEOUT); // Connection timeout
$response_timeout=(empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT); // Response timeout
//print extension_loaded('soap');
if ($proxyuse)
{
$params=array('connection_timeout'=>$timeout,
'response_timeout'=>$response_timeout,
'proxy_use' => 1,
'proxy_host' => $proxyhost,
'proxy_port' => $proxyport,
'proxy_login' => $proxyuser,
'proxy_password' => $proxypass
);
}
else
{
$params=array('connection_timeout'=>$timeout,
'response_timeout'=>$response_timeout,
'proxy_use' => 0,
'proxy_host' => false,
'proxy_port' => false,
'proxy_login' => false,
'proxy_password' => false
);
}
return $params;
}

View File

@ -63,7 +63,11 @@ else
// Set the WebService URL
dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL." WSDL=".$WS_DOL_URL_WSDL);
$soapclient = new nusoap_client($WS_DOL_URL_WSDL,true);
require_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php');
$params=getSoapParams();
//ini_set('default_socket_timeout', $params['response_timeout']);
//$soapclient = new SoapClient($WS_DOL_URL_WSDL,$params);
$soapclient = new nusoap_client($WS_DOL_URL_WSDL,true,$params['proxy_host'],$params['proxy_port'],$params['proxy_login'],$params['proxy_password'],$params['connection_timeout'],$params['response_timeout']);
// Check for an error
$err = $soapclient->getError();