/** * @throws BinLogException */ public function connectToStream() { if (false === ($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) { throw new BinLogException(BinLogException::UNABLE_TO_CREATE_SOCKET . socket_strerror(socket_last_error()), socket_last_error()); } socket_set_block($this->socket); socket_set_option($this->socket, SOL_SOCKET, SO_KEEPALIVE, 1); if (false === socket_connect($this->socket, $this->config->getHost(), $this->config->getPort())) { throw new BinLogException(socket_strerror(socket_last_error()), socket_last_error()); } $this->serverInfo(); $this->auth(); $this->getBinlogStream(); }
/** * @param Config $config * @throws MySQLReplicationException * @throws DBALException * @throws ConfigException * @throws BinLogException */ public function __construct(Config $config) { $config->validate(); $this->connection = DriverManager::getConnection(['user' => $config->getUser(), 'password' => $config->getPassword(), 'host' => $config->getHost(), 'port' => $config->getPort(), 'driver' => 'pdo_mysql', 'charset' => $config->getCharset()]); $this->repository = new MySQLRepository($this->connection); $this->gtiService = new GtidService(); $this->binLogAuth = new BinLogAuth(); $this->socketConnect = new BinLogSocketConnect($config, $this->repository, $this->binLogAuth, $this->gtiService); $this->socketConnect->connectToStream(); $this->jsonBinaryDecoderFactory = new JsonBinaryDecoderFactory(); $this->rowEventService = new RowEventService($config, $this->repository, $this->jsonBinaryDecoderFactory); $this->binaryDataReaderService = new BinaryDataReaderService(); $this->eventDispatcher = new EventDispatcher(); $this->event = new Event($config, $this->socketConnect, $this->binaryDataReaderService, $this->rowEventService, $this->eventDispatcher); }