You are here: Smart Control > Smart Control Classes > Server Instance Class (si)

Server Instance Class (si)

The following are Server Instance parameters. Refer to Server Pool and Server Instance Commands for descriptions.

Parameters

name(string)

probe_port (int)

quiesce (bool)

sp (object): The server pool that this server instance belongs to, as retrieved using srvpool::getByName().

weight (int)

hot_spare (bool)

probe_l4 (bool)

maxconn (int)

persist_override (bool)

strict_maxconn (bool)

Methods

getByName(object srvpool, string name)

 

Description:

Fetch the server instance named ‘name’ from the server pool object srvpool.  The server pool object should have been previously fetched with srvpool::getByName().

 

Returns:

On success: server instance object populated with all of its properties. On failure: An exception with a message and an error code.

 

Example:

// Fetch a server instance named ‘sv00’

$sp = srvpool::getByName(“sp00”);

$si = si::getByName($sp, "sv00");

getStatusDescription()

 

Description:

Get the status of this server instance as a string.

 

Returns:

A string containing the status of this server instance.

 

Example:

$sp = srvpool::getByName(“sp00”);

$si = si::getByName($sp, "sv00");
// print the status – accessible using ‘lastrun’ command.

echo $si->getStatusDescription();

getStatusResp()

 

Description:

Get the status of this server instance as a numeric value.

 

Returns: A numeric value indicating the status:

0: There are no problems with this server instance.

1: There is an ‘informational’ status available, but the server instance is functional.

2: There is a problem with this server instance.

Example:

// If there is a problem with this server instance, print the status (accessible using ‘lastrun’ command).

$sp = srvpool::getByName(“sp00”);

$si = si::getByName($sp, "sv00");

if ($si->getStatusResp() == 2) {

        echo $si->getStatusDescription();

}

getCurrentWeight()

 

Description:

Get the dynamic weight of this server instance as a numeric value.

 

Returns:

A numeric value indicating the weight.

 

Example:

// Print the current weight (accessible using ‘lastrun’ command).

$sp = srvpool::getByName(“sp00”);

$si = si::getByName($sp, "sv00");

if ($si->getStatusResp() == 2) {

        echo $si->getCurrentWeight();

}

stats(string statName)

 

Description:

Get the value of the statistic named ‘statName’.  The available statistics are the same as those displayed in the CLI when using the srvpool <name> si <name> stats command.

 

Returns:

On success, the last-measured value of this statistic. On failure, an exception describing what went wrong: invalid statistic name or no statistic specified.

 

Example:

$sp = srvpool::getByName(“sp00”);

$si = si::getByName($sp, "sv00");

if ($si->stats(“TOTALPRCSD”) > 100) {

        echo “Processed more than 100 requests through sv00”;

}

delete(optional Boolean forceFlag)

 

Description:

Delete this server.  Can only be used on a server instance object which has been retrieved using si::getByName(),and it must not have been modified since the last time that it was retrieved.  If the server instance is in use by another object in the system, the flag forceFlag must be set to ‘TRUE’ in order for it to be deleted.

 

Returns:

Map containing message string with a status code. Status code will be 0 if the deletion was successful and non-zero otherwise.

 

Example:

$sp = srvpool::getByName(“sp00”);

$si = si::getByName($sp, "sv00");

// Try to delete it, if it fails, force the deletion.

$value = $si->delete();

if ($value[“status”] != 0) {

    // Print out the reason for the failure, accessible using ‘lastrun’ command

    echo “Failed to delete because: “, $value[“message”];

    $value = $si->delete(TRUE);

}

commit()

 

Description:

Push the changes to this server instance into the permanent configuration. If this server object was created using getByName(), this operation is treated as a modify. If it was created using the new keyword, it is treated as an addition.

 

Returns:

Map containing message string with a status code. Status code will be 0 if the commit was successful and non-zero otherwise.

 

Example:

// Create a new server, then modify it

$sp = srvpool::getByName(“sp00”);

$si = new si;

$si->sp = $sp;
$si->name = “sv00”;

$si->weight = 10;

$si->commit();

// If we don’t do getByName(), the commit() below would fail with ‘object already exists’ error because the system will try to add this object instead of modify it.

// The server pool must be re-fetched also since it was modified when we added a server instance.

$sp = srvpool::getByName(“sp00”);

$si = $si = si::getByName($sp, "sv00");

$si->weight = 100;

$si->commit();