Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection keep-alive problems

Tags:

linux

php

curl

I have a PHP script "A" that starts another PHP script "B", which runs up to 5 hours. I use the curl function for that. But my problem is that script "A" does not sure hold the connection to the script "B". I have changed the max_execution_time, timeout, socket-timeout, etc... but nothing helps.

Do I need to send a header to the script "B" with curl or something?

$curl_header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text
/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$curl_header[] = "Cache-Control: max-age=0";
$curl_header[] = "Connection: keep-alive";
$curl_header[] = "Keep-Alive: 84600"; 

$url = 'http://test.de/test_B.php';

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_header); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_TIMEOUT, 84600);
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$curl_errno = curl_errno($ch);
curl_close($ch);

`

like image 550
Max Gunter Avatar asked Nov 24 '12 10:11

Max Gunter


People also ask

How long does Connection: keep-alive last?

It sets how long your server should wait for new requests from clients. A value between 7 to 10 seconds is usually ideal. With higher traffic this value can go extremely higher to make sure there is no frequent TCP connection re-initiated.

What does keep alive mean in networking?

A keepalive is a signal sent from one device to another to maintain a connection between the two devices. This may be between a client and a server, but it could apply to any number of devices or technologies.

Is Connection: keep-alive persistent?

HTTP keep-alive, a.k.a., HTTP persistent connection, is an instruction that allows a single TCP connection to remain open for multiple HTTP requests/responses. By default, HTTP connections close after each request.


1 Answers

If the script "B" takes long time to finish it could be useful to put during the execution some echo "something"; flush(); that mantain the connection alive.

It happens to me recently on a similar execution.

like image 161
Gianni Ciccarelli Avatar answered Oct 01 '22 17:10

Gianni Ciccarelli