$count = $session->countClassInstances( $class )

The countClassInstances() function counts the number of objects that exist for a specified class, or those that would be returned by a call to getClassInstances().

 $n = $session->countClassInstances( "Router" );