PHP code example of stanx / fabiang-xmpp

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

    

stanx / fabiang-xmpp example snippets


use Fabiang\Xmpp\Options;
$options = new Options($address);
$options->setUsername($username)
        ->setPassword($password)
        ->setTimeout(10);

$options->setLogger($logger)

use Fabiang\Xmpp\Client;
$client = new Client($options);
// optional connect manually
$client->connect();

use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;

// fetch roster list; users and their groups
$client->send(new Roster);
// set status to online
$client->send(new Presence);

// send a message to another user
$message = new Message;
$message->setMessage('test')
        ->setTo('[email protected]');
$client->send($message);

// join a channel
$channel = new Presence;
$channel->setTo('[email protected]')
        ->setPassword('channelpassword')
        ->setNickName('mynick');
$client->send($channel);

// send a message to the above channel
$message = new Message;
$message->setMessage('test')
        ->setTo('[email protected]')
        ->setType(Message::TYPE_GROUPCHAT);
$client->send($message);

$client->disconnect();