Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Worker\Shared Class Reference

Public Member Functions

 __construct ($workerId)
 
 postMessage ($message)
 
 getInformations ()
 

Protected Attributes

 $_client = null
 

Detailed Description

Class .

Worker frontend, user's API.

Definition at line 49 of file Shared.php.

Constructor & Destructor Documentation

Hoa\Worker\Shared::__construct (   $workerId)

Build a worker pipe.

Parameters
mixed$workerIdWorker ID or a socket client (i.e. a object).
Returns
void
Exceptions

Definition at line 68 of file Shared.php.

69  {
70  if (is_string($workerId)) {
71  $wid = Run::get($workerId);
72  $this->_client = new Socket\Client($wid['socket']);
73 
74  return;
75  } elseif ($workerId instanceof Socket\Client) {
76  $this->_client = $workerId;
77 
78  return;
79  }
80 
81  throw new Exception(
82  'Either you give a worker ID or you give an object of type ' .
83  '\Hoa\Socket\Client, but not anything else; given %s',
84  0,
85  is_object($workerId)
86  ? get_class($workerId)
87  : $workerId
88  );
89 
90  return;
91  }
static get($workerId)
Definition: Run.php:101

Here is the call graph for this function:

Member Function Documentation

Hoa\Worker\Shared::getInformations ( )

Get informations about the shared worker.

Returns
array

Definition at line 116 of file Shared.php.

117  {
118  $this->_client->connect();
119  $this->_client->writeAll(
120  Backend\Shared::pack(
121  Backend\Shared::TYPE_INFORMATIONS,
122  "\0"
123  )
124  );
125  $this->_client->read(2); // skip type.
126  $length = unpack('Nl', $this->_client->read(4));
127  $message = $this->_client->read($length['l']);
128  $this->_client->read(1); // skip eom.
129  $this->_client->disconnect();
130 
131  return unserialize($message);
132  }
Hoa\Worker\Shared::postMessage (   $message)

Post a message to the shared worker.

Parameters
mixed$messageMessage (everything you want).
Returns
void

Definition at line 99 of file Shared.php.

100  {
101  $this->_client->connect();
102  $this->_client->writeAll(Backend\Shared::pack(
103  Backend\Shared::TYPE_MESSAGE,
104  $message
105  ));
106  $this->_client->disconnect();
107 
108  return;
109  }

Member Data Documentation

Hoa\Worker\Shared::$_client = null
protected

Definition at line 56 of file Shared.php.


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