diff --git a/composer.json b/composer.json index 3f12402..40d5578 100644 --- a/composer.json +++ b/composer.json @@ -4,6 +4,7 @@ "keywords": ["Docker", "container", "ReactPHP", "async"], "homepage": "https://github.com/clue/php-docker-react", "license": "MIT", + "version": "0.2.1", "authors": [ { "name": "Christian Lück", diff --git a/src/Client.php b/src/Client.php index e0288b8..356ecf0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -516,6 +516,58 @@ public function containerCopyStream($container, $config) ); } + /** + * Retrieve container resource usage stats + * + * @param string $container container ID + * @param boolean $stream return stream + * @return Promise Promise + * @link https://docs.docker.com/reference/api/docker_remote_api_v1.20/#get-container-stats-based-on-resource-usage + */ + public function containerStats($container, $stream = false) + { + return $this->browser->get( + $this->browser->resolve( + '/containers/{container}/stats{?stream}', + array( + 'container' => $container, + 'stream' => $stream ? 1 : 0 + ) + ) + )->then(array($this->parser, 'expectJson')); + } + + /** + * Retrieve container logs + * + * @param string $container container ID + * @param boolean $follow return stream + * @param boolean $stdout show stdout log. + * @param boolean $stderr show stderr log. + * @param integer $since UNIX timestamp to filter logs. Specifying a timestamp will only output log-entries since that timestamp. + * @param boolean $timestamps include timestamps + * @param integer $tail output specified number of lines at the end of logs + * @return Promise Promise + * @link https://docs.docker.com/reference/api/docker_remote_api_v1.20/#get-container-logs + */ + public function containerLogs($container, $follow = false, $stdout = true, $stderr = true, $since = 0, $timestamps = false, $tail = 'all') + { + return $this->browser->get( + $this->browser->resolve( + '/containers/{container}/logs{?follow,stdout,stderr,since,timestamps,tail}', + array( + 'container' => $container, + 'follow' => $this->boolArg($follow), + 'stdout' => $this->boolArg($stdout), + 'stderr' => $this->boolArg($stderr), + 'since' => $since, + 'timestamps' => $this->boolArg($timestamps), + 'tail' => $tail + ) + ) + )->then(array($this->parser, 'expectPlain')); + } + /** * List images * diff --git a/src/Io/ResponseParser.php b/src/Io/ResponseParser.php index 529ce2b..d24a3c1 100644 --- a/src/Io/ResponseParser.php +++ b/src/Io/ResponseParser.php @@ -16,8 +16,7 @@ public function expectPlain(Response $response) public function expectJson(Response $response) { // application/json - - return json_decode((string)$response->getBody(), true); + return @json_decode((string)$response->getBody(), true, 512, JSON_BIGINT_AS_STRING); } public function expectEmpty(Response $response)