Hoa central
Static Public Member Functions | List of all members
Hoa\Worker\Run Class Reference

Static Public Member Functions

static register ($workerId, $socket)
 
static unregister ($workerId)
 
static get ($workerId)
 
static widExists ($workerId)
 
static find ($workerId)
 

Detailed Description

Class .

Manipulate .wid files.

Definition at line 47 of file Run.php.

Member Function Documentation

static Hoa\Worker\Run::find (   $workerId)
static

Find a .wid.

Parameters
string$workerIdWorker ID.
Returns
string
Exceptions

Definition at line 132 of file Run.php.

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  }
static Hoa\Worker\Run::get (   $workerId)
static

Get a worker ID data.

Parameters
string$workerIdWorker ID.
Returns
string
Exceptions

Definition at line 101 of file Run.php.

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  }

Here is the caller graph for this function:

static Hoa\Worker\Run::register (   $workerId,
  $socket 
)
static

Register a socketable object as a worker ID.

Parameters
string$workerIdWorker ID.
string$socketSocket URI.
Returns
bool
Exceptions

Definition at line 57 of file Run.php.

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  }
static Hoa\Worker\Run::unregister (   $workerId)
static

Unregister a worker ID.

Parameters
string$workerIdWorker ID.
Returns
bool

Definition at line 85 of file Run.php.

86  {
87  if (false === static::widExists($workerId)) {
88  return true;
89  }
90 
91  return @unlink(static::find($workerId));
92  }

Here is the caller graph for this function:

static Hoa\Worker\Run::widExists (   $workerId)
static

Check if a .wid exists.

Parameters
string$workerIdWorker ID.
Returns
bool

Definition at line 120 of file Run.php.

121  {
122  return true === file_exists(static::find($workerId));
123  }

The documentation for this class was generated from the following file: