PHP code example of catapush / xmpp

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

    

catapush / xmpp example snippets


use Xmpp\Xep\Xep0045;

$roomId = 'YourHouse';
$userId = 'Tom';

$options = array(
    'username'  => 'your_username',
    'password'  => 'your_password',
    'host'      => 'example.com',
    'ssl'       => false,
    'port'      => 5222,
    'resource'  => uniqid('', true),
    'mucServer' => 'conference.example.com',
);
$xmpp = new Xep0045($options, $logger);

$xmpp->createRoom($roomId);            // Create the room.
$xmpp->grantMember($roomId, $userId);  // Add a member to the room.
$xmpp->getMemberList($roomId);         // Get member list and there should be only one member.
$xmpp->revokeMember($roomId, $userId); // Remove the only member out from the room.
$xmpp->getMemberList($roomId);         // Get member list and there should be nobody in the room.
$xmpp->destroyRoom($roomId);           // Destroy the room.
$xmpp->disconnect();                   // Disconnect from the server. Important for heavy-loaded servers.