ByteStream
6 days ago
Middleware
6 days ago
Transport
6 days ago
examples
6 days ago
LICENSE.md
6 days ago
README.md
6 days ago
class-client.php
6 days ago
class-clientstate.php
6 days ago
class-connection.php
6 days ago
class-crawler.php
6 days ago
class-httpclientexception.php
6 days ago
class-httperror.php
6 days ago
class-request.php
6 days ago
class-response.php
6 days ago
composer.json
6 days ago
class-connection.php
34 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WordPress\HttpClient; |
| 4 | |
| 5 | class Connection { |
| 6 | |
| 7 | public $request; |
| 8 | public $http_socket; |
| 9 | public $response_buffer = ''; |
| 10 | public $decoded_response_stream = null; |
| 11 | public $started_at = null; |
| 12 | |
| 13 | public function __construct( Request $request ) { |
| 14 | $this->request = $request; |
| 15 | } |
| 16 | |
| 17 | public function consume_buffer( $length = null ) { |
| 18 | if ( null === $length ) { |
| 19 | $length = strlen( $this->response_buffer ); |
| 20 | } |
| 21 | $buffer = substr( $this->response_buffer, 0, $length ); |
| 22 | $this->response_buffer = substr( $this->response_buffer, $length ); |
| 23 | |
| 24 | return $buffer; |
| 25 | } |
| 26 | |
| 27 | public function time_elapsed_ms() { |
| 28 | if ( null === $this->started_at ) { |
| 29 | return 0; |
| 30 | } |
| 31 | return ( microtime( true ) - $this->started_at ) * 1000; |
| 32 | } |
| 33 | } |
| 34 |