A pure PHP IRC client based on ReactPHP.
The client is the heart of the library, this object is used to perform all communication between your application and the IRC server. It will manage the connection to the IRC server and has all functions needed to interact with the server.
use Jerodev\PhpIrcClient\IrcClient;
$client = new IrcClient('irc.server:6667', 'Jerodev');
$client->connect();
$client->connect()
This function opens the connection to the IRC server. Username has to be set before the connection can be opened.
$client->send(string $command)
Sends a raw IRC command directly to the server. This method should only be used if you really know what you are doing, it is recommended to use the built-in functions below.
Name | Type | Description |
---|---|---|
$command |
string | The raw irc command |
$client->join(string $channel)
Joins a specified channel
Name | Type | Description |
---|---|---|
$channel |
string | The name of the channel to join. |
$client->part(string $channel)
Leave a channel. If the specified channel has not yet been joined, nothing will happen.
Name | Type | Description |
---|---|---|
$channel |
string | The name of the channel to part. |
$client->say(string $target, string $message)
Sends a message to a channel or user.
Name | Type | Description |
---|---|---|
$target |
string | A name of a channel staring with # or the nickname of the user to send a message to. |
$message |
string | The message to send to the target. |
The on()
function on the client can be used to register to several different events. This can be done both before and after connecting to the IRC server. Events have variable callback arguments, all are described below.
$client->on('registered', function () { });
Emitted when the server sends the initial welcome message (001
). This indicates that you are connected to the server.
$client->on('motd', function (string $motd) { });
Emitted when the server sends the message of the day to the client. If the message of the day is multiple lines, this event might be emitted multiple times.
Name | Type | Description |
---|---|---|
$motd |
string | The server's Message Of The Day. |
$client->on('topic', function (string $channel, string $topic) { });
Emitted when joining a channel or when the topic of a joined channel changes.
Name | Type | Description |
---|---|---|
$channel |
string | The channel where the topic has changed. |
$topic |
string | The new topic for this channel. |
$client->on('names', function (string $channel, string[] $nicks) { });
Emitted when the server sends a list of nicks for a channel. This happens immediately after joining a channel and on request.
Name | Type | Description |
---|---|---|
$channel |
string | The channel name. |
$names |
string[] | A list of nicknames who are currently in this channel. |
You can also specify the channel you want to listen on by adding
#channel
to the event.
For example:$client->on('names#channel', function ($names) {})
$client->on('message', function (string $from, IrcChannel $channel, string $message) { });
Emitted when a message is sent to a connected channel.
Name | Type | Description |
---|---|---|
$from |
string | The nickname of the user who sent the message. |
$channel |
IrcChannel | The channel where the message was sent. |
$message |
string | The received message. |
You can also specify the channel you want to listen on by adding
#channel
to the event.
For example:$client->on('message#channel', function ($from, $channel, $message) {})
$client->on('ping', function () { });
Emitted when the server sends a ping
request to the client. The pong request has already been sent back to the server before this event is emitted.