Hoa central
Run.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Worker;
38 
47 class Run
48 {
57  public static function register($workerId, $socket)
58  {
59  if (true === static::widExists($workerId)) {
60  throw new Exception(
61  'Worker ID %s already exists, we cannot create it again.',
62  0,
63  $workerId
64  );
65  }
66 
67  file_put_contents(
68  static::find($workerId),
69  serialize([
70  'id' => $workerId,
71  'socket' => $socket,
72  'start' => microtime(true)
73  ])
74  );
75 
76  return true;
77  }
78 
85  public static function unregister($workerId)
86  {
87  if (false === static::widExists($workerId)) {
88  return true;
89  }
90 
91  return @unlink(static::find($workerId));
92  }
93 
101  public static function get($workerId)
102  {
103  if (false === static::widExists($workerId)) {
104  throw new Exception(
105  'Worker ID %s does not exist.',
106  1,
107  $workerId
108  );
109  }
110 
111  return unserialize(file_get_contents(static::find($workerId)));
112  }
113 
120  public static function widExists($workerId)
121  {
122  return true === file_exists(static::find($workerId));
123  }
124 
132  public static function find($workerId)
133  {
134  if (false !== strpos($workerId, '/') ||
135  false !== strpos($workerId, '\\')) {
136  throw new Exception(
137  'Worker ID must not contain / or \ character; given %s.',
138  2,
139  $workerId
140  );
141  }
142 
143  return 'hoa://Data/Variable/Run/' . $workerId . '.wid';
144  }
145 }
static unregister($workerId)
Definition: Run.php:85
static find($workerId)
Definition: Run.php:132
static widExists($workerId)
Definition: Run.php:120