Skip to content

Instantly share code, notes, and snippets.

@MarQuisKnox
Created June 22, 2015 13:07
Show Gist options
  • Select an option

  • Save MarQuisKnox/34b8e7c0d69a5d8023ea to your computer and use it in GitHub Desktop.

Select an option

Save MarQuisKnox/34b8e7c0d69a5d8023ea to your computer and use it in GitHub Desktop.

Revisions

  1. MarQuisKnox created this gist Jun 22, 2015.
    64 changes: 64 additions & 0 deletions xmpp.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?php

    error_reporting( E_ALL & ~E_STRICT );
    ini_set( 'display_errors', true );

    $path = dirname( __FILE__ ).'/library';
    set_include_path(
    get_include_path() . PATH_SEPARATOR . $path
    );

    require_once('Zend/Loader/Autoloader.php');
    $autoloader = Zend_Loader_Autoloader::getInstance();
    $autoloader->setFallbackAutoloader(true);

    // constants
    define('XMPP_PRESENCE', false);
    define('XMPP_HOST', 'example.com');
    define('XMPP_PORT', 5222);
    define('XMPP_USERNAME', 'username');
    define('XMPP_PASSWORD', 'password');
    define('XMPP_RESOURCE', 'xmpphp');
    define('XMPP_SERVER', null);
    define('XMPP_PRINT_LOG', true);
    define('XMPP_ERROR_LEVEL', XMPPHP_Log::LEVEL_VERBOSE);

    // users
    $users = array(
    '[email protected]',
    '[email protected]',
    );

    // message
    $message = 'This is a test message...'. PHP_EOL . 'File: '.__FILE__ . PHP_EOL . 'Line: '.__LINE__;

    echo '<pre>';
    $conn = new XMPPHP_XMPP(
    XMPP_HOST,
    XMPP_PORT,
    XMPP_USERNAME,
    XMPP_PASSWORD,
    XMPP_RESOURCE,
    XMPP_SERVER,
    XMPP_PRINT_LOG,
    XMPP_ERROR_LEVEL
    );

    try {
    $conn->connect();
    $conn->processUntil('session_start');

    if( XMPP_PRESENCE ) {
    $conn->presence();
    }

    if( !empty( $users ) ) {
    foreach( $users AS $key => $value ) {
    $conn->message( $value, $message );
    }
    }

    $conn->disconnect();
    } catch(XMPPHP_Exception $e) {
    die($e->getMessage());
    }