1. Go to this page and download the library: Download hivellm/umicp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hivellm / umicp example snippets
UMICP\Core\{Envelope, Matrix, OperationType};
use UMICP\Transport\MultiplexedPeer;
// Create an envelope
$envelope = new Envelope(
from: 'my-app',
to: 'server',
operation: OperationType::DATA,
capabilities: ['action' => 'hello']
);
echo $envelope->serialize(); // JSON output
use UMICP\Core\{Envelope, Matrix, OperationType};
use UMICP\Transport\MultiplexedPeer;
use React\EventLoop\Loop;
// Envelope
$envelope = new Envelope(
from: 'client',
to: 'server',
operation: OperationType::DATA,
capabilities: ['msg' => 'Hello!']
);
$json = $envelope->serialize();
// Matrix (11 operations)
$matrix = new Matrix();
$dotProduct = $matrix->dotProduct([1,2,3], [4,5,6]);
$similarity = $matrix->cosineSimilarity($vec1, $vec2);
// Multiplexed Peer (P2P)
$peer = new MultiplexedPeer('my-peer', Loop::get(), ['port' => 20081]);
$peer->on('data', fn($env, $p) => $peer->sendToPeer($p->id, $resp));
$peer->connectToPeer('ws://localhost:20082/umicp');
bash
# All tests
./test-all.sh
# Or individual
./vendor/bin/phpunit # All tests
./vendor/bin/phpunit --testsuite=Unit
./vendor/bin/phpunit --testsuite=Integration
php benchmark.php # Performance
php verify-implementation.php # Verification