Skip to content

Commit 0ab51e8

Browse files
authored
Consistently use socket path (php-pm#320)
* Fix slave socket path usage * Make ProcessClient name consistent * Move socketpath to required parameters
1 parent 124f017 commit 0ab51e8

6 files changed

Lines changed: 24 additions & 15 deletions

File tree

src/Commands/StatusCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPPM\Commands;
44

5-
use PHPPM\Client;
5+
use PHPPM\ProcessClient;
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Input\InputOption;
@@ -33,7 +33,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3333
{
3434
$config = $this->initializeConfig($input, $output, false);
3535

36-
$handler = new Client();
36+
$handler = new ProcessClient();
3737
$handler->setSocketPath($config['socket-path']);
3838
$handler->getStatus(function ($status) use ($output) {
3939
$output->writeln($this->parseStatus($status));

src/Commands/StopCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
namespace PHPPM\Commands;
44

5-
// use PHPPM\ProcessManager;
6-
use PHPPM\Client;
5+
use PHPPM\ProcessClient;
76
use Symfony\Component\Console\Command\Command;
87
use Symfony\Component\Console\Input\InputInterface;
98
use Symfony\Component\Console\Input\InputOption;
@@ -35,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3534
{
3635
$config = $this->initializeConfig($input, $output, false);
3736

38-
$handler = new Client();
37+
$handler = new ProcessClient();
3938
$handler->setSocketPath($config['socket-path']);
4039

4140
$handler->stopProcessManager(function ($status) use ($output) {

src/Client.php renamed to src/ProcessClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use React\Socket\UnixConnector;
88
use React\Socket\ConnectionInterface;
99

10-
class Client
10+
class ProcessClient
1111
{
1212
use ProcessCommunicationTrait;
1313

src/ProcessCommunicationTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ protected function getControllerSocketPath($overwrite = true)
125125
return $this->getSockFile('controller', $overwrite);
126126
}
127127

128+
/**
129+
* @return string
130+
*/
131+
public function getSocketPath()
132+
{
133+
return $this->socketPath;
134+
}
135+
128136
/**
129137
* @param string $socketPath
130138
*/

src/ProcessManager.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ public function run()
378378
ob_implicit_flush(1);
379379

380380
$this->loop = Factory::create();
381-
$this->controllerHost = $this->getControllerSocketPath();
382-
$this->controller = new UnixServer($this->controllerHost, $this->loop);
381+
$this->controller = new UnixServer($this->getControllerSocketPath(), $this->loop);
383382
$this->controller->on('connection', array($this, 'onSlaveConnection'));
384383

385384
$this->web = new Server(sprintf('%s:%d', $this->host, $this->port), $this->loop);
@@ -860,13 +859,13 @@ protected function newSlaveInstance($port)
860859
$this->output->writeln(sprintf("Start new worker #%d", $port));
861860
}
862861

862+
$socketpath = var_export($this->getSocketPath(), true);
863863
$bridge = var_export($this->getBridge(), true);
864864
$bootstrap = var_export($this->getAppBootstrap(), true);
865865

866866
$config = [
867867
'port' => $port,
868868
'session_path' => session_save_path(),
869-
'controllerHost' => $this->controllerHost,
870869

871870
'app-env' => $this->getAppEnv(),
872871
'debug' => $this->isDebug(),
@@ -894,7 +893,7 @@ protected function newSlaveInstance($port)
894893
}
895894
896895
//global for all global functions
897-
ProcessSlave::\$slave = new ProcessSlave($bridge, $bootstrap, $config);
896+
ProcessSlave::\$slave = new ProcessSlave($socketpath, $bridge, $bootstrap, $config);
898897
ProcessSlave::\$slave->run();
899898
EOF;
900899

src/ProcessSlave.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ class ProcessSlave
117117
*/
118118
protected $config;
119119

120-
public function __construct($bridgeName = null, $appBootstrap, array $config = [])
120+
public function __construct($socketpath, $bridgeName = null, $appBootstrap, array $config = [])
121121
{
122-
$this->config = $config;
123-
$this->appBootstrap = $appBootstrap;
122+
$this->setSocketPath($socketpath);
123+
124124
$this->bridgeName = $bridgeName;
125-
$this->baseServer = $_SERVER;
125+
$this->appBootstrap = $appBootstrap;
126+
$this->config = $config;
126127

127128
if ($this->config['session_path']) {
128129
session_save_path($this->config['session_path']);
@@ -303,7 +304,9 @@ public function run()
303304
ErrorHandler::register(new ErrorHandler($this->errorLogger));
304305

305306
$connector = new UnixConnector($this->loop);
306-
$connector->connect($this->config['controllerHost'])->done(
307+
$unixSocket = $this->getControllerSocketPath(false);
308+
309+
$connector->connect($unixSocket)->done(
307310
function($controller) {
308311
$this->controller = $controller;
309312

0 commit comments

Comments
 (0)