How to use unix domain sockets with the Zend Framework

Using the client

$client = new Client();
$client->setUri('unix:///run/docker.sock:/v1.13/version');
$client->setOptions(array(
    'maxredirects' => 0,
    'timeout'      => 30
));
$response = $client->send();
echo $response->getContent();
{"ApiVersion":"1.14","Arch":"amd64","GitCommit":"fa7b24f","GoVersion":"go1.3.1","KernelVersion":"3.16.1-1-ARCH","Os":"linux","Version":"1.2.0"}

Using the socket

$uri = new Zend\Uri\SocketHttp\SocketHttp("unix:///run/docker.sock:/v1.13/version");
$socket = new Client\Adapter\Socket();
$socket->setOptions(array(
    'maxredirects' => 0,
    'timeout' => 30,
));
$socket->connect($uri->getHost(), 0, false, true);
$socket->write('GET', $uri);
$str = $socket->read();
HTTP/1.1 200 OK
Content-Type: application/json
Job-Name: version
Date: Thu, 28 Aug 2014 22:33:17 GMT
Content-Length: 144

{"ApiVersion":"1.14","Arch":"amd64","GitCommit":"fa7b24f","GoVersion":"go1.3.1","KernelVersion":"3.16.1-1-ARCH","Os":"linux","Version":"1.2.0"}

2 Comments

  1. Valuable data. Privileged myself I came across your site inadvertently, with this particular amazed the key reason why the following coincidence wouldn’t took place beforehand! My partner and i added them.

  2. Really This blog is awesome! I was searching over search engines and found your blog site. Well I like your high-quality blog site design plus your posting abilities. Keep doing it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>