-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection: keep-alive #22
base: master
Are you sure you want to change the base?
Conversation
. ReadLength for responses with Content-Length header . ReadChunks for response with Content-Transfer-Encoding: chunked . HttpInputStream will handle the "otherwise" case
Needs to be set explicitely by API users, retaining BC
Saw this today in a header enumeration:
https://tools.ietf.org/id/draft-thomson-hybi-http-timeout-01.html#rfc.section.2 Non-standard, but seems to have widespread support; we should consider this in the future. |
public function connect($connectTimeout, $readTimeout) { | ||
if (false === $this->reuseable) { | ||
$this->socket->close(); | ||
} else if ($this->socket->isConnected()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check enough? If the server closes the connection (e.g. because of a timeout on a reused connection), we would probably receive an EOF
here, but isConnected()
would still be true,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this actually is a problem; and it seems eof()
could help here. In need of some more real-life testing!
|
||
use peer\SocketInputStream; | ||
|
||
class Channel implements \io\streams\InputStream { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class needs some tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script used for integration testing timeouts and reconnection behaviors:
<?php namespace keep_alive;
use peer\http\HttpConnection;
use util\cmd\Console;
use io\streams\Streams;
use lang\Throwable;
$c= new HttpConnection($argv[1]);
for ($i= 0; $i < 10; $i++) {
try {
$r= $c->get([], ['Connection' => 'keep-alive']);
Console::writeLine(date('r'), ': ', $r);
Streams::readAll($r->in());
} catch (Throwable $t) {
Console::writeLine(date('r'), ': ', $t);
}
$delay= rand(100, 6000);
Console::writeLinef('ZZ %.3f seconds', $delay / 1000);
usleep($delay * 1000);
}
I think this is ready to get some real-life exposure; this could go into applications as: "require" : {
"xp-framework/http": "dev-feature/keep-alive as 9.1.0"
} |
Improves performance of
peer.http.SocketHttpTransport
by implementing keep-alive semantics.Performance
Same script as in #21, 100 queries using the Neo4J REST API:
Usage
Users need to pass the keep-alive header explicitely, for example as follows: