3.2. Querying timeservers
Prev | Chapter 3. Zend_TimeSync | Next

## 3.2. Querying timeservers

General information about querying timeservers goes here.

### 3.2.1. Basic NTP query

Querying the time from a NTP server with a standard port

    <?php
    $server = new Zend_TimeSync('ntp://serveraddress', 'alias');
    $result = $server->getDate();

    echo $result->getIso();

### 3.2.2. Basic SNTP query

Querying the time from a SNTP server with a standard port

    <?php
    $server = new Zend_TimeSync('sntp://serveraddress', 'alias');
    $result = $server->getDate();

    echo $result->getIso();

### 3.2.3. Using the fallback mechanism

Querying the time from an NTP server with a standard port, and a list of NTP/SNTP fallback servers provided:

    <?php
    $serverlist = array('alias_a' => 'ntp://address',
                        'alias_b' => 'ntp://address',
                        'alias_c' => 'sntp://address');

    $server = new Zend_TimeSync($serverlist);
    $result = $server->getDate();

    echo $result->getIso();

Querying the time from an NTP server with a non standard port, and with a list of NTP/SNTP fallback servers that run on a non standard port:

    <?php
    $serverlist = array('alias_a' => 'ntp://address:2222',
                        'alias_b' => 'ntp://address:2222',
                        'alias_c' => 'sntp://address:3333');

    $server = new Zend_TimeSync($serverlist);
    $result = $server->getDate();

    echo $result->getIso();

### 3.2.4. Taking care of exceptions

Taking care of exceptions:

    <?php
    $serverlist = array(
            // invalid servers
            'server_a'  => 'ntp://be.foo.bar.org',
            'server_b'  => 'sntp://be.foo.bar.org',
    );

    $server = new Zend_TimeSync($serverlist);

    try {
        $result = $server->getDate();
        echo $result->getIso();
    } catch (Zend_TimeSync_Exception $e) {

        $exceptions = $e->get();

        foreach ($exceptions as $key => $myException) {
            echo $myException->getMessage();
            echo '<br />';
        }
    }

Prev | Up | Next
Chapter 3. Zend_TimeSync | Home | Chapter 4. Zend_Translate