示例#1
0
 public function testSendReceive()
 {
     // Create the mailbox
     $receiver = new Receiver('/tmp/ipc_test');
     // Send a message to it
     $sender = new Sender('/tmp/ipc_test');
     $sender->send("Test message");
     // Make sure we don't wait for the message, incase something is wrong.
     $receiver->waitForMessage(false);
     // Receive the message
     $msg = null;
     $receiver->run(function ($message, $type) use(&$msg) {
         $msg = $message;
         return false;
     });
     // Check the message
     $this->assertEquals("Test message", $msg);
 }
示例#2
0
<?php

require_once __DIR__ . '/../src/Sender.php';
require_once __DIR__ . '/../src/Exception.php';
use Blamh\IPC\Sender;
// Send a message to it
$sender = new Sender('/tmp/ipc_test');
while (1) {
    $u = microtime();
    print "Sending: {$u}\n";
    $sender->send($u);
    usleep(mt_rand(100000, 800000));
}