public static function take_screenshot($force = false)
 {
     if (pts_module::read_file('is_running') == 'yes' || $force) {
         $ss_file = pts_module::save_dir() . 'screenshot-' . date('ymd-His') . '.png';
         shell_exec('import -window root ' . $ss_file);
         if (is_file($ss_file)) {
             array_push(self::$screenshots, $ss_file);
             return $ss_file;
         }
     }
     return false;
 }
 private static function save_log_offsets($type)
 {
     foreach (self::$to_monitor as &$sensor) {
         $log_f = pts_module::read_file('logs/' . phodevi::sensor_object_identifier($sensor));
         $offset = count(explode(PHP_EOL, $log_f));
         if ($type === 'interim') {
             self::$test_run_tries_offsets[self::$test_run_try_number][phodevi::sensor_object_identifier($sensor)] = $offset;
         } else {
             if ($type === 'pre-test') {
                 self::$individual_test_run_offsets[phodevi::sensor_object_identifier($sensor)] = $offset;
             }
         }
     }
 }
 private static function parse_monitor_log($log_file, $start_offset = 0)
 {
     $log_f = pts_module::read_file($log_file);
     $line_breaks = explode(PHP_EOL, $log_f);
     $results = array();
     for ($i = 0; $i < $start_offset && isset($line_breaks[$i]); $i++) {
         unset($line_breaks[$i]);
     }
     foreach ($line_breaks as $line) {
         $line = trim($line);
         if (!empty($line) && $line >= 0) {
             array_push($results, $line);
         }
     }
     if (count($results) > 0 && max($results) == 0) {
         $results = array();
     }
     return $results;
 }
 protected static function setup_server_addressing($server_string = null)
 {
     if (isset($server_string[0]) && strpos($server_string[0], '/', strpos($server_string[0], ':')) > 6) {
         pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to Phoromatic Server: ' . $server_string[0]);
         self::$account_id = substr($server_string[0], strrpos($server_string[0], '/') + 1);
         self::$server_address = substr($server_string[0], 0, strpos($server_string[0], ':'));
         self::$server_http_port = substr($server_string[0], strlen(self::$server_address) + 1, -1 - strlen(self::$account_id));
         pts_client::$display->generic_heading('Server IP: ' . self::$server_address . PHP_EOL . 'Server HTTP Port: ' . self::$server_http_port . PHP_EOL . 'Account ID: ' . self::$account_id);
         pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);
     } else {
         if (($last_server = trim(pts_module::read_file('last-phoromatic-server'))) && !empty($last_server)) {
             pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to last server connection: ' . $last_server);
             $last_account_id = substr($last_server, strrpos($last_server, '/') + 1);
             $last_server_address = substr($last_server, 0, strpos($last_server, ':'));
             $last_server_http_port = substr($last_server, strlen($last_server_address) + 1, -1 - strlen($last_account_id));
             pts_client::$pts_logger && pts_client::$pts_logger->log('Last Server IP: ' . $last_server_address . ' Last Server HTTP Port: ' . $last_server_http_port . ' Last Account ID: ' . $last_account_id);
             for ($i = 0; $i < 10; $i++) {
                 $server_response = phoromatic::upload_to_remote_server(array('r' => 'ping'), $last_server_address, $last_server_http_port, $last_account_id);
                 $server_response = json_decode($server_response, true);
                 if ($server_response && isset($server_response['phoromatic']['ping'])) {
                     self::$server_address = $last_server_address;
                     self::$server_http_port = $last_server_http_port;
                     self::$account_id = $last_account_id;
                     pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection restored');
                     pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);
                     break;
                 } else {
                     pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection failed');
                     sleep(12 * ($i + 1));
                 }
             }
         }
     }
     if (self::$server_address == null) {
         $archived_servers = pts_client::available_phoromatic_servers();
         if (!empty($archived_servers)) {
             pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Servers');
             self::attempt_phoromatic_server_auto_discover($archived_servers);
         }
     }
     if (self::$server_address == null || self::$server_http_port == null || self::$account_id == null) {
         pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection setup failed');
         echo PHP_EOL . 'You must pass the Phoromatic Server information as an argument to phoromatic.connect, or otherwise configure your network setup.' . PHP_EOL . '      e.g. phoronix-test-suite phoromatic.connect 192.168.1.2:5555/I0SSJY' . PHP_EOL . PHP_EOL;
         if (PTS_IS_DAEMONIZED_SERVER_PROCESS && !empty($archived_servers)) {
             echo 'The Phoromatic client appears to be running as a system service/daemon so will attempt to continue auto-polling to find the Phoromatic Server.' . PHP_EOL . PHP_EOL;
             $success = false;
             do {
                 pts_client::$pts_logger && pts_client::$pts_logger->log('Will auto-poll connected servers every 90 seconds looking for a claim by a Phoromatic Server');
                 sleep(90);
                 $success = self::attempt_phoromatic_server_auto_discover($archived_servers);
             } while ($success == false);
         } else {
             return false;
         }
     }
     return true;
 }
 private static function save_log_offsets($type)
 {
     foreach (self::$to_monitor as &$sensor) {
         $log_f = pts_module::read_file('logs/' . phodevi::sensor_object_identifier($sensor));
         $offset = count(explode(PHP_EOL, $log_f)) - 1;
         // as log file ends with an empty line
         if ($type === 'try') {
             self::$test_run_tries_offsets[phodevi::sensor_object_identifier($sensor)][self::$test_run_try_number] = $offset;
         } else {
             if ($type === 'run') {
                 self::$individual_test_run_offsets[phodevi::sensor_object_identifier($sensor)] = $offset;
             }
         }
     }
 }