Skip to content
This repository was archived by the owner on Feb 12, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/nsqphp/Connection/ConnectionManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace nsqphp\Connection;

class ConnectionManager extends ConnectionPool
{
private function __construct()
{
}

public static function getInstance()
{
static $instance;
if (!$instance) {
$instance = new self;
}
return $instance;
}
}
23 changes: 14 additions & 9 deletions src/nsqphp/nsqphp.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,26 @@ public function publishTo($hosts, $cl = NULL)
if (!is_array($hosts)) {
$hosts = explode(',', $hosts);
}
$cm = Connection\ConnectionManager::getInstance();
foreach ($hosts as $h) {
if (strpos($h, ':') === FALSE) {
$h .= ':4150';
}

$parts = explode(':', $h);
$conn = new Connection\Connection(
$parts[0],
isset($parts[1]) ? $parts[1] : NULL,
$this->connectionTimeout,
$this->readWriteTimeout,
$this->readWaitTimeout,
FALSE, // blocking
array($this, 'connectionCallback')
);
$conn = $cm->find($h);
if (!$conn) {
$conn = new Connection\Connection(
$parts[0],
isset($parts[1]) ? $parts[1] : NULL,
$this->connectionTimeout,
$this->readWriteTimeout,
$this->readWaitTimeout,
FALSE, // blocking
array($this, 'connectionCallback')
);
$cm->add($conn);
}
$this->pubConnectionPool->add($conn);
}

Expand Down