How to use run_connection method of phoromatic class

Best Phoronix-test-suite code snippet using phoromatic.run_connection

phoromatic.php

Source:phoromatic.php Github

copy

Full Screen

...40 return 'The Phoromatic module contains the client support for interacting with Phoromatic and Phoromatic Tracker services.';41 }42 public static function user_commands()43 {44 return array('connect' => 'run_connection', 'explore' => 'explore_network', 'upload_result' => 'upload_unscheduled_result', 'set_root_admin_password' => 'set_root_admin_password', 'list_results' => 'recent_phoromatic_server_results', 'clone' => 'clone_phoromatic_server_result', 'export_results_for_account_schedules' => 'generate_export_result_schedule_dump');45 }46 public static function upload_unscheduled_result($args)47 {48 $server_setup = self::setup_server_addressing($args);49 if(!$server_setup)50 return false;51 $uploads = 0;52 foreach($args as $arg)53 {54 if(pts_types::is_result_file($arg))55 {56 $uploads++;57 echo PHP_EOL . 'Uploading: ' . $arg . PHP_EOL;58 $result_file = pts_types::identifier_to_object($arg);59 $server_response = self::upload_test_result($result_file);60 $server_response = json_decode($server_response, true);61 if(isset($server_response['phoromatic']['response']))62 echo ' Result Uploaded' . PHP_EOL;63 else64 echo ' Upload Failed' . PHP_EOL;65 }66 }67 if($uploads == 0)68 echo PHP_EOL . 'No Result Files Found To Upload.' . PHP_EOL;69 }70 public static function set_root_admin_password()71 {72 phoromatic_server::prepare_database();73 $root_admin_pw = phoromatic_server::read_setting('root_admin_pw');74 if($root_admin_pw != null)75 {76 do77 {78 $check_root_pw = pts_user_io::prompt_user_input('Please enter the existing root-admin password');79 }80 while(hash('sha256', 'PTS' . $check_root_pw) != $root_admin_pw);81 }82 echo PHP_EOL . 'The new root-admin password must be at least six characters long.' . PHP_EOL;83 do84 {85 $new_root_pw = pts_user_io::prompt_user_input('Please enter the new root-admin password');86 }87 while(strlen($new_root_pw) < 6);88 $new_root_pw = hash('sha256', 'PTS' . $new_root_pw);89 $root_admin_pw = phoromatic_server::save_setting('root_admin_pw', $new_root_pw);90 }91 public static function generate_export_result_schedule_dump($r)92 {93 phoromatic_server::prepare_database();94 if(isset($r[0]) && !empty($r[0]))95 {96 phoromatic_server::generate_result_export_dump($r[0]);97 }98 }99 public static function explore_network()100 {101 pts_client::$display->generic_heading('Phoromatic Servers');102 $archived_servers = pts_client::available_phoromatic_servers();103 $server_count = 0;104 foreach($archived_servers as $archived_server)105 {106 $response = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/server.php?phoromatic_info');107 if(!empty($response))108 {109 $response = json_decode($response, true);110 if($response && isset($response['pts']))111 {112 $server_count++;113 echo PHP_EOL . 'IP: ' . $archived_server['ip'] . PHP_EOL;114 echo 'HTTP PORT: ' . $archived_server['http_port'] . PHP_EOL;115 echo 'WEBSOCKET PORT: ' . $response['ws_port'] . PHP_EOL;116 echo 'SERVER: ' . $response['http_server'] . PHP_EOL;117 echo 'PHORONIX TEST SUITE: ' . $response['pts'] . ' [' . $response['pts_core'] . ']' . PHP_EOL;118 // TODO XXX fix/finish below code...119 if(false && ($ws = new phoromatic_client_comm_ws($archived_server['ip'], $response['ws_port'])))120 {121 // Query the WebSocket Server for some Phoromatic Server details122 $s = $ws->send(array('phoromatic' => array('event' => 'pts-version')));123 $s = $ws->send(array('phoromatic' => array('event' => 'download-cache')));124 $r = $ws->receive_until('download-cache');125 var_dump($r);126 }127 else128 {129 // Provide some other server info via HTTP130 $repo = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/download-cache.php?repo');131 echo 'DOWNLOAD CACHE: ';132 if(!empty($repo))133 {134 $repo = json_decode($repo, true);135 if($repo && isset($repo['phoronix-test-suite']['download-cache']))136 {137 $total_file_size = 0;138 foreach($repo['phoronix-test-suite']['download-cache'] as $file_name => $inf)139 {140 $total_file_size += $repo['phoronix-test-suite']['download-cache'][$file_name]['file_size'];141 }142 echo count($repo['phoronix-test-suite']['download-cache']) . ' FILES / ' . round($total_file_size / 1000000) . ' MB CACHE SIZE';143 }144 }145 else146 {147 echo 'N/A';148 }149 }150 echo PHP_EOL;151 $repo = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/openbenchmarking-cache.php?repos');152 echo 'SUPPORTED OPENBENCHMARKING.ORG REPOSITORIES:' . PHP_EOL;153 if(!empty($repo))154 {155 $repo = json_decode($repo, true);156 if($repo && is_array($repo['repos']))157 {158 foreach($repo['repos'] as $data)159 {160 echo ' ' . $data['title'] . ' - Last Generated: ' . date('d M Y H:i', $data['generated']) . PHP_EOL;161 }162 }163 }164 else165 {166 echo ' N/A' . PHP_EOL;167 }168 }169 }170 }171 if($server_count == 0)172 {173 echo PHP_EOL . 'No Phoromatic Servers detected.' . PHP_EOL . PHP_EOL;174 }175 }176 protected static function tick_thread()177 {178 static $last_phoromatic_log = 0;179 while(true)180 {181 $j = array();182 $log_size = pts_client::$pts_logger->get_log_file_size();183 if($log_size != $last_phoromatic_log)184 {185 $phoromatic_log = file_get_contents(pts_client::$pts_logger->get_log_file_location());186 $last_phoromatic_log = $log_size;187 $j['phoromatic']['client-log'] = $phoromatic_log;188 }189 foreach(phodevi::supported_sensors() as $sensor)190 {191 $j['phoromatic']['stats']['sensors'][phodevi::sensor_name($sensor)] = array('value' => phodevi::read_sensor($sensor), 'unit' => phodevi::read_sensor_unit($sensor));192 }193 $j['phoromatic']['stats']['uptime'] = ceil(phodevi::system_uptime() / 60);194 $server_response = phoromatic::upload_to_remote_server(array(195 'r' => 'tick',196 'j' => json_encode($j),197 ));198 $server_response = json_decode($server_response, true);199 if($server_response && isset($server_response['phoromatic']['tick_thread']))200 {201 switch($server_response['phoromatic']['tick_thread'])202 {203 case 'reboot':204 if(pts_client::executable_in_path('reboot'))205 {206 shell_exec('reboot');207 }208 break;209 case 'halt-testing':210 touch(PTS_USER_PATH . 'halt-testing');211 break;212 }213 }214 // Randomize the thread work a little bit to ensure not hitting the systems at the same time215 sleep(rand(60, 90));216 }217 }218 protected static function upload_to_remote_server($to_post, $server_address = null, $server_http_port = null, $account_id = null)219 {220 static $last_communication_minute = null;221 static $communication_attempts = 0;222 if($last_communication_minute == date('i') && $communication_attempts > 8)223 {224 // Something is wrong, Phoromatic shouldn't be communicating with server more than four times a minute225 return false;226 }227 else228 {229 if(date('i') != $last_communication_minute)230 {231 $last_communication_minute = date('i');232 $communication_attempts = 0;233 }234 $communication_attempts++;235 }236 if($server_address == null && self::$server_address != null)237 {238 $server_address = self::$server_address;239 }240 if($server_http_port == null && self::$server_http_port != null)241 {242 $server_http_port = self::$server_http_port;243 }244 if($account_id == null && self::$account_id != null)245 {246 $account_id = self::$account_id;247 }248 $to_post['aid'] = $account_id;249 $to_post['pts'] = PTS_VERSION;250 $to_post['pts_core'] = PTS_CORE_VERSION;251 $to_post['gsid'] = defined('PTS_GSID') ? PTS_GSID : null;252 $to_post['lip'] = pts_network::get_local_ip();253 $to_post['h'] = phodevi::system_hardware(true);254 $to_post['nm'] = pts_network::get_network_mac();255 $to_post['nw'] = implode(', ', pts_network::get_network_wol());256 $to_post['s'] = phodevi::system_software(true);257 $to_post['n'] = phodevi::read_property('system', 'hostname');258 $to_post['msi'] = PTS_MACHINE_SELF_ID;259 return pts_network::http_upload_via_post('http://' . $server_address . ':' . $server_http_port . '/phoromatic.php', $to_post, false);260 }261 protected static function update_system_status($current_task, $estimated_time_remaining = 0, $percent_complete = 0, $for_schedule = null, $estimate_to_next_comm = 0)262 {263 static $last_msg = null;264 // Avoid an endless flow of "idling" messages, etc265 if($current_task != $last_msg)266 pts_client::$pts_logger && pts_client::$pts_logger->log($current_task);267 $last_msg = $current_task;268 if(self::$limit_network_communication)269 {270 static $last_comm_time = 0;271 if(time() > ($last_comm_time + 800 + rand(0, 180)))272 {273 // It's been at least half hour since last update, so report in state...274 $last_comm_time = time();275 }276 else277 {278 return;279 }280 }281 return phoromatic::upload_to_remote_server(array(282 'r' => 'update_system_status',283 'a' => $current_task,284 'time' => $estimated_time_remaining,285 'pc' => $percent_complete,286 'sched' => (!empty($for_schedule) ? $for_schedule : self::$p_schedule_id),287 'bid' => (!empty(self::$benchmark_ticket_id) ? self::$benchmark_ticket_id : 0),288 'o' => $estimate_to_next_comm289 ));290 }291 public static function startup_ping_check($server_ip, $http_port)292 {293 $server_response = phoromatic::upload_to_remote_server(array(294 'r' => 'ping',295 ), $server_ip, $http_port);296 }297 protected static function setup_server_addressing($server_string = null)298 {299 self::$has_run_server_setup_func = true;300 if(isset($server_string[0]) && strpos($server_string[0], '/', strpos($server_string[0], ':')) > 6)301 {302 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to Phoromatic Server: ' . $server_string[0]);303 self::$account_id = substr($server_string[0], strrpos($server_string[0], '/') + 1);304 self::$server_address = substr($server_string[0], 0, strpos($server_string[0], ':'));305 self::$server_http_port = substr($server_string[0], strlen(self::$server_address) + 1, -1 - strlen(self::$account_id));306 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);307 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);308 }309 else if(($last_server = trim(pts_module::read_file('last-phoromatic-server'))) && !empty($last_server))310 {311 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to last server connection: ' . $last_server);312 $last_account_id = substr($last_server, strrpos($last_server, '/') + 1);313 $last_server_address = substr($last_server, 0, strpos($last_server, ':'));314 $last_server_http_port = substr($last_server, strlen($last_server_address) + 1, -1 - strlen($last_account_id));315 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);316 for($i = 0; $i < 10; $i++)317 {318 $server_response = phoromatic::upload_to_remote_server(array(319 'r' => 'ping',320 ), $last_server_address, $last_server_http_port, $last_account_id);321 $server_response = json_decode($server_response, true);322 if($server_response && isset($server_response['phoromatic']['ping']))323 {324 self::$server_address = $last_server_address;325 self::$server_http_port = $last_server_http_port;326 self::$account_id = $last_account_id;327 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection restored');328 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);329 break;330 }331 else332 {333 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection failed');334 sleep((12 * ($i + 1)));335 }336 }337 }338 if(self::$server_address == null)339 {340 $archived_servers = pts_client::available_phoromatic_servers();341 if(!empty($archived_servers))342 {343 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Servers');344 self::attempt_phoromatic_server_auto_discover($archived_servers);345 }346 }347 if(self::$server_address == null || self::$server_http_port == null || self::$account_id == null)348 {349 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection setup failed');350 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;351 if(PTS_IS_DAEMONIZED_SERVER_PROCESS && !empty($archived_servers))352 {353 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;354 $success = false;355 do356 {357 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');358 sleep(90);359 $success = self::attempt_phoromatic_server_auto_discover($archived_servers);360 }361 while($success == false);362 }363 else364 {365 return false;366 }367 }368 return true;369 }370 protected static function attempt_phoromatic_server_auto_discover(&$phoromatic_servers)371 {372 foreach($phoromatic_servers as &$archived_server)373 {374 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Server on: ' . $archived_server['ip'] . ': ' . $archived_server['http_port']);375 $server_response = phoromatic::upload_to_remote_server(array(376 'r' => 'ping',377 ), $archived_server['ip'], $archived_server['http_port']);378 $server_response = json_decode($server_response, true);379 if($server_response && isset($server_response['phoromatic']['account_id']))380 {381 self::$server_address = $archived_server['ip'];382 self::$server_http_port = $archived_server['http_port'];383 self::$account_id = $server_response['phoromatic']['account_id'];384 return true;385 }386 }387 return false;388 }389 protected static function setup_system_environment()390 {391 if(is_writable('/boot/grub/grubenv') && pts_client::executable_in_path('grub-editenv'))392 {393 // In case system fails or reboots in process and don't want to hang on GRUB recordfail394 shell_exec('grub-editenv /boot/grub/grubenv unset recordfail 2>&1');395 }396 }397 public static function run_connection($args)398 {399 if(pts_client::create_lock(PTS_USER_PATH . 'phoromatic_lock') == false)400 {401 trigger_error('Phoromatic is already running.', E_USER_ERROR);402 return false;403 }404 define('PHOROMATIC_PROCESS', true);405 if(pts_client::$pts_logger == false)406 {407 pts_client::$pts_logger = new pts_logger();408 }409 pts_client::$pts_logger->log(pts_core::program_title(true) . ' [' . PTS_CORE_VERSION . '] starting Phoromatic client');410 if(phodevi::system_uptime() < 60)411 {...

Full Screen

Full Screen

run_connection

Using AI Code Generation

copy

Full Screen

1$phoromatic = new phoromatic();2$phoromatic->run_connection();3$phoromatic = new phoromatic();4$phoromatic->run_connection();5$phoromatic = new phoromatic();6$phoromatic->run_connection();7$phoromatic->get_connection();8$phoromatic = new phoromatic();9$phoromatic->run_connection();10$phoromatic = new phoromatic();11$phoromatic->run_connection();12$phoromatic = new phoromatic();13$phoromatic->run_connection();14$phoromatic = new phoromatic();15$phoromatic->run_connection();16$connection = $phoromatic->get_connection();17$result = $connection->query("SELECT * FROM users");18$phoromatic = new phoromatic();19$phoromatic->run_connection();20$phoromatic = new phoromatic();21$phoromatic->run_connection();

Full Screen

Full Screen

run_connection

Using AI Code Generation

copy

Full Screen

1$phoromatic = new phoromatic();2$phoromatic->run_connection();3$phoromatic = new phoromatic();4$phoromatic->run_connection();5$phoromatic = new phoromatic();6$phoromatic->run_connection();7$phoromatic = new phoromatic();8$phoromatic->run_connection();9$phoromatic = new phoromatic();10$phoromatic->run_connection();11$phoromatic = new phoromatic();12$phoromatic->run_connection();13$phoromatic = new phoromatic();14$phoromatic->run_connection();15$phoromatic = new phoromatic();16$phoromatic->run_connection();17$phoromatic = new phoromatic();

Full Screen

Full Screen

run_connection

Using AI Code Generation

copy

Full Screen

1$phoromatic = new phoromatic();2$phoromatic->run_connection();3$phoromatic = new phoromatic();4$phoromatic->run_connection();5$phoromatic = new phoromatic();6$phoromatic->run_connection();7$phoromatic = new phoromatic();8$phoromatic->run_connection();9$phoromatic = new phoromatic();10$phoromatic->run_connection();11$phoromatic = new phoromatic();12$phoromatic->run_connection();13$phoromatic = new phoromatic();14$phoromatic->run_connection();15$phoromatic = new phoromatic();16$phoromatic->run_connection();17$phoromatic = new phoromatic();18$phoromatic->run_connection();19$phoromatic = new phoromatic();20$phoromatic->run_connection();21$phoromatic = new phoromatic();22$phoromatic->run_connection();23$phoromatic = new phoromatic();24$phoromatic->run_connection();25$phoromatic = new phoromatic();26$phoromatic->run_connection();

Full Screen

Full Screen

run_connection

Using AI Code Generation

copy

Full Screen

1require_once 'phoromatic.php';2$phoromatic = new Phoromatic();3$phoromatic->run_connection();4require_once 'phoromatic.php';5$phoromatic = new Phoromatic();6$phoromatic->run_connection();7require_once 'phoromatic.php';8$phoromatic = new Phoromatic();9$phoromatic->run_connection();10require_once 'phoromatic.php';11$phoromatic = new Phoromatic();12$phoromatic->run_connection();13require_once 'phoromatic.php';14$phoromatic = new Phoromatic();15$phoromatic->run_connection();16require_once 'phoromatic.php';17$phoromatic = new Phoromatic();18$phoromatic->run_connection();19require_once 'phoromatic.php';20$phoromatic = new Phoromatic();21$phoromatic->run_connection();22require_once 'phoromatic.php';23$phoromatic = new Phoromatic();24$phoromatic->run_connection();25require_once 'phoromatic.php';26$phoromatic = new Phoromatic();27$phoromatic->run_connection();28require_once 'phoromatic.php';29$phoromatic = new Phoromatic();30$phoromatic->run_connection();31require_once 'phoromatic.php';32$phoromatic = new Phoromatic();33$phoromatic->run_connection();

Full Screen

Full Screen

run_connection

Using AI Code Generation

copy

Full Screen

1require_once 'phoromatic.php';2$phoromatic = new phoromatic();3$phoromatic->run_connection();4require_once 'phoromatic.php';5$phoromatic = new phoromatic();6$phoromatic->run_connection();7require_once 'phoromatic.php';8$phoromatic = new phoromatic();9$phoromatic->run_connection();10require_once 'phoromatic.php';11$phoromatic = new phoromatic();12$phoromatic->run_connection();13require_once 'phoromatic.php';14$phoromatic = new phoromatic();15$phoromatic->run_connection();16require_once 'phoromatic.php';17$phoromatic = new phoromatic();18$phoromatic->run_connection();19require_once 'phoromatic.php';20$phoromatic = new phoromatic();21$phoromatic->run_connection();22require_once 'phoromatic.php';23$phoromatic = new phoromatic();24$phoromatic->run_connection();25require_once 'phoromatic.php';26$phoromatic = new phoromatic();27$phoromatic->run_connection();28require_once 'phoromatic.php';29$phoromatic = new phoromatic();30$phoromatic->run_connection();31require_once 'phoromatic.php';32$phoromatic = new phoromatic();33$phoromatic->run_connection();

Full Screen

Full Screen

run_connection

Using AI Code Generation

copy

Full Screen

1require_once('phoromatic.php');2$phoromatic = new Phoromatic();3$phoromatic->run_connection();4require_once('phoromatic.php');5$phoromatic = new Phoromatic();6$phoromatic->run_connection();7require_once('phoromatic.php');8$phoromatic = new Phoromatic();9$phoromatic->run_connection();10require_once('phoromatic.php');11$phoromatic = new Phoromatic();12$phoromatic->run_connection();13require_once('phoromatic.php');14$phoromatic = new Phoromatic();15$phoromatic->run_connection();16require_once('phoromatic.php');17$phoromatic = new Phoromatic();18$phoromatic->run_connection();19require_once('phoromatic.php');20$phoromatic = new Phoromatic();21$phoromatic->run_connection();22require_once('phoromatic.php');23$phoromatic = new Phoromatic();24$phoromatic->run_connection();25require_once('phoromatic.php');

Full Screen

Full Screen

run_connection

Using AI Code Generation

copy

Full Screen

1$phoromatic = new phoromatic();2$phoromatic->run_connection();3{4 public function db_connection()5 {6 $conn = mysqli_connect("localhost","root","","phoromatic");7 return $conn;8 }9 public function run_connection()10 {11 $conn = $this->db_connection();12 $sql = "SELECT * FROM `phoromatic`";13 $result = $conn->query($sql);14 if ($result->num_rows > 0) {15 while($row = $result->fetch_assoc()) {16 echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["email"]. "<br>";17 }18 } else {19 echo "0 results";20 }21 }22}23$phoromatic = new phoromatic();24$phoromatic->run_connection();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful