Skip to content

Commit

Permalink
Fixed shared memory writing and fork losing received messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ghola committed Mar 17, 2016
1 parent 530fcf5 commit 605499e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/Spork/Fork.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Fork implements DeferredInterface
private $name;
private $status;
private $message;
private $messages = array();

public function __construct($pid, SharedMemory $shm, $debug = false)
{
Expand Down Expand Up @@ -92,17 +93,15 @@ public function processWaitStatus($status)

public function receive()
{
$messages = array();

foreach ($this->shm->receive() as $message) {
if ($message instanceof ExitMessage) {
$this->message = $message;
} else {
$messages[] = $message;
$this->messages[] = $message;
}
}

return $messages;
return $this->messages;
}

public function kill($signal = SIGINT)
Expand Down Expand Up @@ -135,6 +134,11 @@ public function getError()
}
}

public function getMessages()
{
return $this->messages;
}

public function isSuccessful()
{
return 0 === $this->getExitStatus();
Expand Down
2 changes: 1 addition & 1 deletion src/Spork/SharedMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function send($message, $signal = null, $pause = 500)
if (($shmId = @shmop_open($this->pid, 'a', 0, 0)) > 0) {
// Read any existing messages in shared memory
$readMessage = shmop_read($shmId, 0, shmop_size($shmId));
$messageArray[] = unserialize($readMessage);
$messageArray = unserialize($readMessage);
shmop_delete($shmId);
shmop_close($shmId);
}
Expand Down

0 comments on commit 605499e

Please sign in to comment.