PHP code example of hoa / irc

1. Go to this page and download the library: Download hoa/irc 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/ */

    

hoa / irc example snippets


$uri    = 'irc://chat.freenode.net';
$client = new Hoa\Irc\Client(new Hoa\Socket\Client($uri));

$client->on('open', function (Hoa\Event\Bucket $bucket) {
    $bucket->getSource()->join('Gordon', '#hoaproject');

    return;
});

$client->on('mention', function (Hoa\Event\Bucket $bucket) {
    $data    = $bucket->getData();
    $message = $data['message']; // do something with that.

    $bucket->getSource()->say(
        $data['from']['nick'] . ': What?'
    );

    return;
});

$client->run();

$ircUri = 'irc://chat.freenode.net';
$wsUri  = 'ws://127.0.0.1:8889';

$group  = new Hoa\Socket\Connection\Group();
$client = new Hoa\Irc\Client(new Hoa\Socket\Client($ircUri));
$server = new Hoa\Websocket\Server(new Hoa\Socket\Server($wsUri));

$group[] = $server;
$group[] = $client;

$server->on('message', function (Hoa\Event\Bucket $bucket) use ($client) {
    $data = $bucket->getData();
    $client->say($data['message']);

    return;
});

$group->run();