Skip to content

Commit 6132f62

Browse files
committed
Merge pull request #2 from cursedcoder/customSock
Custom directory for sockets.
2 parents e9eaba9 + fe5855e commit 6132f62

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

EProcess/Adapter/BaseAdapter.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ public function __construct(LoopInterface $loop)
1717

1818
protected function createUnixSocket()
1919
{
20-
$unixFile = sprintf('tmp/%s.sock', $this->node);
20+
if (!defined('EPROCESS_SOCKET_DIR')) {
21+
throw new \Exception("EPROCESS_SOCKET_DIR is not defined.");
22+
}
23+
24+
if (!defined('EPROCESS_AUTOLOAD')) {
25+
throw new \Exception('EPROCESS_AUTOLOAD is not defined.');
26+
}
27+
28+
if (!is_writable(EPROCESS_SOCKET_DIR)) {
29+
throw new \Exception(sprintf("Cannot write to %s.", EPROCESS_SOCKET_DIR));
30+
}
31+
32+
$unixFile = sprintf('%s/%s.sock', EPROCESS_SOCKET_DIR, $this->node);
2133
$unix = sprintf('unix://%s', $unixFile);
2234

23-
$cleanup = function() use ($unixFile) {
35+
$cleanup = function () use ($unixFile) {
2436
$this->loop->stop();
2537
@unlink($unixFile);
2638
};
@@ -32,5 +44,6 @@ protected function createUnixSocket()
3244
}
3345

3446
abstract public function create($class, array $data = []);
47+
3548
abstract public function kill();
3649
}

examples/autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(ticks = 1);
44

55
define('EPROCESS_AUTOLOAD', __FILE__);
6+
define('EPROCESS_SOCKET_DIR', '/tmp/eprocess');
67

78
$loader = require __DIR__ . '/../vendor/autoload.php';
89

0 commit comments

Comments
 (0)