mirror of
https://github.com/predis/predis.git
synced 2026-08-27 10:34:10 +00:00
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Predis\Network;
|
|
|
|
use Predis\ConnectionParameters;
|
|
use Predis\CommunicationException;
|
|
|
|
class UnixDomainSocketConnection extends TcpConnection {
|
|
protected function checkParameters(ConnectionParameters $parameters) {
|
|
if ($parameters->scheme != 'unix') {
|
|
throw new \InvalidArgumentException("Invalid scheme: {$parameters->scheme}");
|
|
}
|
|
$pathToSocket = $parameters->path;
|
|
if (!isset($pathToSocket)) {
|
|
throw new \InvalidArgumentException('Missing UNIX domain socket path');
|
|
}
|
|
if (!file_exists($pathToSocket)) {
|
|
throw new \InvalidArgumentException("Could not find $pathToSocket");
|
|
}
|
|
return $parameters;
|
|
}
|
|
|
|
protected function createResource() {
|
|
$uri = sprintf('unix:///%s', $this->_params->path);
|
|
$connectFlags = STREAM_CLIENT_CONNECT;
|
|
if ($this->_params->connection_persistent) {
|
|
$connectFlags |= STREAM_CLIENT_PERSISTENT;
|
|
}
|
|
$this->_socket = @stream_socket_client(
|
|
$uri, $errno, $errstr, $this->_params->connection_timeout, $connectFlags
|
|
);
|
|
if (!$this->_socket) {
|
|
$this->onCommunicationException(trim($errstr), $errno);
|
|
}
|
|
}
|
|
}
|