In PHP, a script is making a cURL request to a web service and then reusing the handle to perform more requests to the same web service. Sniffing the connection, I see that it works fine until like the 140th request (the number varies). Then it seems to send no data to the server and it responds with a bad request. If the script keeps trying to perform the requests, it starts to send garbage, the following requests are just strings like this one:
W47Sj47cDxTYW4gTHVpcztEPjtwPFNhbnRhIENydXo7Wj47cDxTYW50YSBGZTtTPjtwPFNhbnRpYWdvIERlbCBFc3Rlcm87Rz47cDxUaWVycmEgRGVsIEZ1ZWdvO1Y%2BO3A8VHVjdW1hbjtUPjs%2BPjs%2BOzs%2BO3Q8cDw7cDxsPG9uRm9jdXM7PjtsP(...)RDYW5jZWxhcicsJycpXDs7Pj4%2BOzs%2BOz4%2BOz4%2BO2w8Y2hrTm9TdW1pbmlzdHJhTWFpbDtjaGtGYWN0dXJhY2lvbjtpbWdCdG5GaWx0cm9GYWN0Oz4%2BaPpaTHB5VO%2ByKbxCglGRNS2EaFE%3D&rblTipoPersona=F&txtNombre=ANIBAL&txtApellido=LAJARA&txtNroDoc=23964779&txtFechaNac=27%2F07%2F1974&txtMail=anibal-nob%40hotmail.com&chkFacturacion=o(...)cmbTipoDoc=1&cmbSexo=M&cmbCicloFacturacion=02&cmbProvinciasFact=S&cmbLocalidadesFact=14244
which looks like just part of the data without headers (dots added by me).
I could (and I will) just reset the connection if I get a bad request response, but I would like to find out why this happens.
What could cause this? Are there limits to how many times a cURL handle can be reused, or how much data a single handle/php instance can transfer or something?
Code is like this:
$ch=curl_init();
while($running) {
$vars=array(what i need to send);
$url='http://something/';
$opts=array();
$opts[CURLOPT_RETURNTRANSFER]=true;
$opts[CURLOPT_FAILONERROR]=false;
$opts[CURLOPT_FORBID_REUSE]=false;
$opts[CURLOPT_FRESH_CONNECT]=false;
$opts[CURLOPT_AUTOREFERER]=true;
$opts[CURLOPT_ENCODING]='gzip,deflate';
$opts[CURLOPT_TIMEOUT]=0;
$opts[CURLOPT_CONNECTTIMEOUT]=0;
$opts[CURLOPT_HTTPHEADER]=array(
'Expect:',
'Connection: Keep-Alive',
'Keep-Alive: 3600'
);
$opts[CURLOPT_HEADER]=true;
$opts[CURLOPT_POST]=true;
$opts[CURLOPT_POSTFIELDS]=$vars;
$opts[CURLOPT_URL]=$url;
$opts[CURLOPT_FOLLOWLOCATION]=true;
curl_setopt_array($ch,$opts);
$res=curl_exec($ch);
...
}
The script is being executed from CLI without execution time limit.