PHP code example of jeffreyroberts / phergie-irc-client-react
1. Go to this page and download the library: Download jeffreyroberts/phergie-irc-client-react 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/ */
jeffreyroberts / phergie-irc-client-react example snippets
$connection = new \Phergie\Irc\Connection();
// ...
$client = new \Phergie\Irc\Client\React\Client();
$client->on('irc.received', function($message, $write, $connection, $logger) {
if ($message['command'] !== 'JOIN') {
return;
}
$channel = $message['params']['channels'];
$nick = $message['nick'];
$write->ircPrivmsg($channel, 'Welcome ' . $nick . '!');
});
$client->run($connection);
// Also works:
// $client->run(array($connection1, ..., $connectionN));
// Also possible:
// Don't autorun the event loopin case you pass your own event loop and run it yourself
// $client->run($connection, false);
$client->on('connect.before.all', function(array $connections) {
// ...
});
$client->on('connect.after.all', function(array $connections, array $writes) {
// ...
});
$client->on('connect.before.each', function(\Phergie\Irc\ConnectionInterface $connection) {
// ...
});
$client->on('connect.after.each', function(\Phergie\Irc\ConnectionInterface $connection, \Phergie\Irc\Client\React\WriteStream $write) {
// ...
});
$client->on('connect.error', function(
\Exception $message,
\Phergie\Irc\ConnectionInterface $connection,
\Psr\Log\LoggerInterface $logger
) use ($client) {
$logger->debug('Connection to ' . $connection->getServerHostname() . ' lost: ' . $e->getMessage());
});
$client->on('connect.end', function(\Phergie\Irc\ConnectionInterface $connection, \Psr\Log\LoggerInterface $logger) use ($client) {
$logger->debug('Connection to ' . $connection->getServerHostname() . ' lost, attempting to reconnect');
$client->addConnection($connection);
});
$client->on('irc.received', function(
array $message,
\Phergie\Irc\Client\React\WriteStream $write,
\Phergie\Irc\ConnectionInterface $connection,
\Psr\Log\LoggerInterface $logger
) {
// ...
});
$client->on('irc.sent', function(
$message,
\Phergie\Irc\Client\React\WriteStream $write,
\Phergie\Irc\ConnectionInterface $connection,
\Psr\Log\LoggerInterface $logger
) {
// ...
});
$client->on('irc.tick', function(
\Phergie\Irc\Client\React\WriteStream $write,
\Phergie\Irc\ConnectionInterface $connection,
\Psr\Log\LoggerInterface $logger
) {
// ...
});
$client->addTimer(5, function() {
// ...
});
$client->addPeriodicTimer(5, function() {
// ...
});
$connection->setOption('force-ipv4', true);
$connection->setOption('allow-self-signed', true);
$connection->setOption('transport', 'ssl');
curl -s https://getcomposer.org/installer | php
php composer.phar install
./vendor/bin/phpunit