Open the connection manually using fsockopen()
so you can control the timing of sending the request and closing the connection.
$conn = fsockopen("stackoverflow.com", 80);
$request = "GET / HTTP/1.1
" +
"Host: stackoverflow.com
" +
"Connection: keep-alive
";
fputs($conn, $request);
$response = fgets($conn);
sleep(30);
close($conn);
Connection: keep-alive
tells the server to keep the connection open until the client closes it (this is actually the default in HTTP/1.1, but no harm in sending it explicitly).
However, most webservers have an inactivity timeout that will close connections that are idle. According to Wikipedia this defaults to 15 seconds in Apache httpd 1.3 and 2.0, and 5 seconds in httpd 2.2. So it's likely that the above code won't be effective. You would have to keep sending new requests every couple of seconds to keep the server from closing the connection.