An unofficial PHP extension that allows you to use the protocol Aeron.
Before installing and using this extension, you must have Aeron installed.
git clone --branch 1.38.2 --depth 1 https://github.com/real-logic/aeron.git
sudo apt update
sudo apt install cmake g++ default-jdk libbsd-dev uuid-dev doxygen graphviz
mkdir --parents aeron/cppbuild/Debug
cd aeron/cppbuild/Debug
cmake -DCMAKE_BUILD_TYPE=Debug ../..
cmake --build . --clean-first
You can speed up the build by setting the
cmake --build
command to the maximum number of parallel
processes using the parameter--parallel
ctest
sudo cmake --install .
sudo ldconfig
By default, CMake will install the library in
/usr/local
. You can change the installation directory with the option--prefix
It will be convenient to run the media driver as a service systemd:
[Unit]
Description=Aeron Media Driver
After=network.target
[Service]
User=ubuntu
ExecStart=/home/ubuntu/aeron/cppbuild/Debug/binaries/aeronmd
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
The media driver uses shared memory in its work. But
systemd
by default removes it after the user logs out. To avoid this, set theRemoveIPC=no
parameter in the file/etc/systemd/logind.conf
Install php dev
sudo apt install php8.0-dev
Clone the repository and go to it and execute this commands
phpize
./configure
make
sudo make install
In the directory /etc/php/8.0/mods-available
create a file aeron.ini
with the content extension=aeron.so
Run command sudo phpenmod -v8.0 aeron
Check aeron version:
php --ri aeron
If the installation is successful, the aeron.so
file will be created and placed in
PHP module directory. You will need to add
line extension=aeron.so
in php.ini
before using this module.
If you don't have phpize
on your system, make sure you have the appropriate developer version of the PHP package installed, as they
often contain a phpize
command with the appropriate header files for building PHP and its modules.
For more information, use the phpize --help command.
<?php
use Aeron\Publisher;
$publisher = new Publisher(
channel: 'aeron:udp?endpoint=localhost:20121', // string
stream_id: 1001, // int
);
$result = $publisher->offer(message: 'Hello, World!');
$publisher->close();
<?php
use Aeron\Subscriber;
function handler(string $message): void
{
echo "<<$message>>", PHP_EOL;
}
$subscriber = new Subscriber(
handler: 'handler', // callable
channel: 'aeron:udp?endpoint=localhost:20121', // string
stream_id: 1001, // int
);
$fragments_read = $subscriber->poll();
$subscriber->close();