PHP code example of ratchetio / ratchetio

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

    

ratchetio / ratchetio example snippets


// installs global error and exception handlers
Ratchetio::init(array('access_token' => 'your_access_token'));

try {
    throw new Exception('test exception');
} catch (Exception $e) {
    Ratchetio::report_exception($e);
}

Ratchetio::report_message('testing 123', 'info');

// raises an E_NOTICE which will be reported by the error handler
$foo = $bar;

// will be reported by the exception handler
throw new Exception('test 2');



$config = array(
    // ur_ratchetio_access_token',
    // optional - environment name. any string will do.
    'environment' => 'production',
    // optional - dir your code is in. used for linking stack traces.
    'root' => '/Users/brian/www/myapp',
    // optional - max error number to report. defaults to -1 (report all errors)
    'max_errno' => E_USER_NOTICE  // ignore E_STRICT and above
);
Ratchetio::init($config);

$set_exception_handler = false;
$set_error_handler = false;
Ratchetio::init($config, $set_exception_handler, $set_error_handler);

try {
    do_something();
} catch (Exception $e) {
    Ratchetio::report_exception($e);
}

Ratchetio::report_message('could not connect to mysql server', 'warning');
Ratchetio::report_message('Here is a message with some additional data', 'info', 
    array('x' => 10, 'code' => 'blue'));

$config['error_sample_rates'] = array(
    // E_WARNING omitted, so defaults to 1
    E_NOTICE => 0.1,
    E_USER_ERROR => 0.5,
    // E_USER_WARNING will take the same value, 0.5
    E_USER_NOTICE => 0.1,
    // E_STRICT and beyond will all be 0.1
);

function get_current_user() {
    if ($_SESSION['user_id']) {
        return array(
            'id' => $_SESSION['user_id'], //  // optional - value is a string
        );
    }
    return null;
}
$config['person_fn'] = 'get_current_user';