How to use internet_support_available method of pts_network class

Best Phoronix-test-suite code snippet using pts_network.internet_support_available

pts_openbenchmarking.php

Source:pts_openbenchmarking.php Github

copy

Full Screen

...87 }88 public static function is_openbenchmarking_result_id($id)89 {90 $is_id = false;91 if(self::is_string_openbenchmarking_result_id_compliant($id) && pts_network::internet_support_available())92 {93 $json_response = pts_openbenchmarking::make_openbenchmarking_request('is_openbenchmarking_result', array('i' => $id));94 $json_response = json_decode($json_response, true);95 if(is_array($json_response) && isset($json_response['openbenchmarking']['result']['valid']) && $json_response['openbenchmarking']['result']['valid'] == 'TRUE')96 {97 $is_id = true;98 }99 }100 return $is_id;101 }102 public static function clone_openbenchmarking_result(&$id, $return_xml = false)103 {104 if(!pts_network::internet_support_available())105 {106 return false;107 }108 $json_response = pts_openbenchmarking::make_openbenchmarking_request('clone_openbenchmarking_result', array('i' => $id));109 $json_response = json_decode($json_response, true);110 $valid = false;111 if(is_array($json_response) && isset($json_response['openbenchmarking']['result']['composite_xml']))112 {113 $composite_xml = $json_response['openbenchmarking']['result']['composite_xml'];114 $result_file = new pts_result_file($composite_xml);115 $result_file->set_reference_id($id);116 //$id = strtolower($id);117 $valid = $return_xml ? $result_file->get_xml() : pts_client::save_test_result($id . '/composite.xml', $result_file->get_xml(), true);118 if(PTS_IS_CLIENT && $json_response['openbenchmarking']['result']['system_logs_available'])119 {120 // Fetch the system logs and toss them into the results directory system-logs/121 pts_openbenchmarking::clone_openbenchmarking_result_system_logs($id, pts_client::setup_test_result_directory($id), $json_response['openbenchmarking']['result']['system_logs_available']);122 }123 }124 else if(PTS_IS_CLIENT && isset($json_response['openbenchmarking']['result']['error']))125 {126 trigger_error($json_response['openbenchmarking']['result']['error'], E_USER_ERROR);127 }128 return $valid;129 }130 public static function clone_openbenchmarking_result_system_logs(&$id, $extract_to, $sha1_compare = null)131 {132 if(!pts_network::internet_support_available())133 {134 return false;135 }136 $system_log_response = pts_openbenchmarking::make_openbenchmarking_request('clone_openbenchmarking_system_logs', array('i' => $id));137 $extracted = false;138 if($system_log_response != null)139 {140 $zip_temp = pts_client::create_temporary_file();141 file_put_contents($zip_temp, $system_log_response);142 if($sha1_compare == null || sha1_file($zip_temp) == $sha1_compare)143 {144 // hash check of file passed or was null145 $extracted = pts_compression::zip_archive_extract($zip_temp, $extract_to);146 }147 unlink($zip_temp);148 }149 return $extracted;150 }151 public static function is_string_openbenchmarking_result_id_compliant($id)152 {153 $valid = false;154 if(strlen($id) == 22)155 {156 $segments = explode('-', $id);157 if(count($segments) == 3)158 {159 if(strlen($segments[0]) == 7 && is_numeric($segments[0]))160 {161 $us = strlen($segments[1]);162 if($us > 1 && $us < 9 && pts_strings::is_alnum($segments[1]))163 {164 if(pts_strings::is_alnum($segments[2]))165 {166 $valid = true;167 }168 }169 }170 }171 }172 return $valid;173 }174 public static function is_abstract_id($id)175 {176 $valid = false;177 if(strlen($id) == 4)178 {179 if(pts_strings::is_alpha($id))180 {181 $valid = true;182 }183 }184 return $valid;185 }186 public static function openbenchmarking_host()187 {188 static $host = null;189 if($host == null)190 {191 // Use HTTPS if OpenSSL is available as a check to see if HTTPS can be handled192 // OpenSSL seems to have problems on OpenIndiana at least, TODO: investigate193 // Using a proxy seems to have problems for HTTPS194 // TODO XXX195 //$host = ((extension_loaded('openssl') && getenv('NO_OPENSSL') == false && php_uname('s') == 'Linux' && (!PTS_IS_CLIENT || !pts_network::is_proxy_setup())) ? 'https://' : 'http://') . 'openbenchmarking.org/';196 $host = 'http://openbenchmarking.org/';197 }198 return $host;199 }200 public static function refresh_repository_lists($repos = null, $force_refresh = false)201 {202 if($repos == null)203 {204 if($force_refresh == false)205 {206 if(!defined('HAS_REFRESHED_OBO_LIST'))207 {208 pts_define('HAS_REFRESHED_OBO_LIST', true);209 }210 else211 {212 return true;213 }214 }215 $repos = self::linked_repositories();216 }217 foreach($repos as $repo_name)218 {219 pts_file_io::mkdir(PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name);220 if($repo_name == 'local')221 {222 // Local is a special case, not actually a real repository223 continue;224 }225 if(!is_dir(PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name))226 {227 mkdir(PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name, 0777, true);228 }229 $index_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name . '.index';230 $server_index = null;231 if(is_file($index_file))232 {233 $repo_index = json_decode(file_get_contents($index_file), true);234 $generated_time = $repo_index['main']['generated'];235 // Refreshing the indexes once every few days should be suffice236 // Refresh approximately every three days by default237 $index_cache_ttl = 3;238 if(PTS_IS_CLIENT && ($config_ttl = pts_config::read_user_config('PhoronixTestSuite/Options/OpenBenchmarking/IndexCacheTTL')))239 {240 if($config_ttl === 0)241 {242 // if the value is 0, only rely upon manual refreshes243 continue;244 }245 else if(is_numeric($config_ttl) && $config_ttl >= 1)246 {247 $index_cache_ttl = $config_ttl;248 }249 }250 if($generated_time > (time() - (86400 * $index_cache_ttl)) && $force_refresh == false && (!defined('FIRST_RUN_ON_PTS_UPGRADE') || FIRST_RUN_ON_PTS_UPGRADE == false))251 {252 // The index is new enough253 continue;254 }255 if(pts_network::internet_support_available())256 {257 $server_index = pts_openbenchmarking::make_openbenchmarking_request('repo_index', array('repo' => $repo_name));258 self::$openbenchmarking_index_refreshed = true;259 }260 if(!$server_index && $phoromatic_cache_index = self::phoromatic_server_ob_cache_request('index', $repo_name))261 {262 // Ensure the Phoromatic cache has a newer version of the index than what's currently on the system263 $repo_index = json_decode($phoromatic_cache_index, true);264 if(isset($repo_index['main']['generated']))265 {266 $cache_generated_time = $repo_index['main']['generated'];267 if($cache_generated_time > $generated_time)268 {269 $server_index = $phoromatic_cache_index;270 }271 self::$openbenchmarking_index_refreshed = true;272 }273 }274 }275 else if(pts_network::internet_support_available())276 {277 $server_index = pts_openbenchmarking::make_openbenchmarking_request('repo_index', array('repo' => $repo_name));278 self::$openbenchmarking_index_refreshed = true;279 }280 if(!$server_index && $phoromatic_cache_index = self::phoromatic_server_ob_cache_request('index', $repo_name))281 {282 $server_index = $phoromatic_cache_index;283 }284 if($server_index != null && json_decode($server_index) != false)285 {286 file_put_contents($index_file, $server_index);287 }288 else if(PTS_IS_CLIENT && is_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $repo_name . '.index'))289 {290 copy('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $repo_name . '.index', $index_file);291 }292 if(!is_file($index_file))293 {294 static $reported_read_failure_notice;295 if(!isset($reported_read_failure_notice[$repo_name]) && PTS_IS_CLIENT)296 {297 trigger_error('Failed To Fetch OpenBenchmarking.org Repository Data: ' . $repo_name, E_USER_WARNING);298 $reported_read_failure_notice[$repo_name] = true;299 }300 }301 }302 }303 public static function openbenchmarking_has_refreshed()304 {305 return self::$openbenchmarking_index_refreshed;306 }307 public static function linked_repositories()308 {309 $repos = array('local', 'pts', 'system');310 if(PTS_IS_CLIENT && pts_openbenchmarking_client::user_name() != false)311 {312 $repos[] = pts_openbenchmarking_client::user_name();313 }314 $on_system_indexes = glob(PTS_OPENBENCHMARKING_SCRATCH_PATH . '*.index');315 foreach($on_system_indexes as $index)316 {317 $index = basename($index, '.index');318 pts_arrays::unique_push($repos, $index);319 }320 return $repos;321 }322 public static function make_openbenchmarking_request($request, $post = array())323 {324 $url = pts_openbenchmarking::openbenchmarking_host() . 'f/client.php';325 $to_post = array_merge(array(326 'r' => $request,327 'client_version' => PTS_CORE_VERSION,328 'gsid' => (defined('PTS_GSID') ? PTS_GSID : null),329 'gsid_e' => (defined('PTS_GSID_E') ? PTS_GSID_E : null)330 ), $post);331 if(PTS_IS_CLIENT && ($account = pts_openbenchmarking_client::get_openbenchmarking_account()) && is_array($account))332 {333 $to_post = array_merge($to_post, $account);334 }335 return pts_network::http_upload_via_post($url, $to_post);336 }337 public static function is_repository($repo_name)338 {339 return is_file(PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name . '.index');340 }341 public static function read_repository_index($repo_name, $do_decode = true)342 {343 static $caches;344 static $last_cache_times;345 if($do_decode && isset($caches[$repo_name]) && $last_cache_times[$repo_name] > (time() - 60))346 {347 return $caches[$repo_name];348 }349 $index_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name . '.index';350 if(is_file($index_file))351 {352 $index_file = file_get_contents($index_file);353 if($do_decode)354 {355 $index_file = json_decode($index_file, true);356 }357 }358 else359 {360 $index_file = null;361 }362 if($do_decode)363 {364 $caches[$repo_name] = $index_file;365 $last_cache_times[$repo_name] = time();366 }367 return $index_file;368 }369 public static function download_test_profile($qualified_identifier)370 {371 if(is_file(PTS_TEST_PROFILE_PATH . $qualified_identifier . '/test-definition.xml'))372 {373 return true;374 }375 $file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip';376 if(!is_file($file))377 {378 $cache_locations = array('/var/cache/phoronix-test-suite/openbenchmarking.org/');379 foreach($cache_locations as $cache_location)380 {381 // Assuming if file is present that the SHA1 checksum is fine382 // otherwise add: && ($hash_check == null || sha1_file($cache_location . $qualified_identifier . '.zip') == $hash_check)383 if(is_file($cache_location . $qualified_identifier . '.zip'))384 {385 copy($cache_location . $qualified_identifier . '.zip', $file);386 break;387 }388 }389 }390 if(!is_file($file))391 {392 if(pts_network::internet_support_available())393 {394 $hash_json = pts_openbenchmarking::make_openbenchmarking_request('test_hash', array('i' => $qualified_identifier));395 $hash_json = json_decode($hash_json, true);396 $hash_check = isset($hash_json['openbenchmarking']['test']['hash']) ? $hash_json['openbenchmarking']['test']['hash'] : null; // should also check for ['openbenchmarking']['test']['error'] problems397 $test_profile = pts_openbenchmarking::make_openbenchmarking_request('download_test', array('i' => $qualified_identifier));398 if($test_profile != null && ($hash_check == null || $hash_check == sha1($test_profile)))399 {400 // save it401 file_put_contents($file, $test_profile);402 $hash_check = null;403 }404 }405 if(!is_file($file) && $test_profile = self::phoromatic_server_ob_cache_request('test', substr($qualified_identifier, 0, strpos($qualified_identifier, '/')), substr($qualified_identifier, strpos($qualified_identifier, '/') + 1)))406 {407 if($b64 = base64_decode($test_profile))408 {409 $test_profile = $b64;410 }411 file_put_contents($file, $test_profile);412 }413 if(PTS_IS_CLIENT && !is_file($file))414 {415 trigger_error('Network support is needed to obtain ' . $qualified_identifier . ' data.' . PHP_EOL, E_USER_ERROR);416 return false;417 }418 }419 if(!is_file(PTS_TEST_PROFILE_PATH . $qualified_identifier . '/test-definition.xml') && is_file($file))420 {421 // extract it422 pts_file_io::mkdir(PTS_TEST_PROFILE_PATH . dirname($qualified_identifier));423 pts_file_io::mkdir(PTS_TEST_PROFILE_PATH . $qualified_identifier);424 pts_compression::zip_archive_extract($file, PTS_TEST_PROFILE_PATH . $qualified_identifier);425 if(is_file(PTS_TEST_PROFILE_PATH . $qualified_identifier . '/test-definition.xml'))426 {427 return true;428 }429 else430 {431 unlink($file);432 return false;433 }434 }435 return false;436 }437 public static function phoromatic_server_ob_cache_request($type_request, $repo = null, $test = null)438 {439 if(PTS_IS_CLIENT == false)440 {441 return null;442 }443 $archived_servers = pts_client::available_phoromatic_servers();444 foreach($archived_servers as $archived_server)445 {446 $cache = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/openbenchmarking-cache.php?' . $type_request . '&repo=' . $repo . '&test=' . $test);447 if(!empty($cache))448 {449 return $cache;450 }451 }452 return null;453 }454 public static function available_tests($download_tests = true, $all_versions = false, $append_versions = false, $show_deprecated_tests = false)455 {456 $available_tests = array();457 foreach(self::linked_repositories() as $repo)458 {459 $repo_index = pts_openbenchmarking::read_repository_index($repo);460 if(isset($repo_index['tests']) && is_array($repo_index['tests']))461 {462 foreach(array_keys($repo_index['tests']) as $identifier)463 {464 if(!$show_deprecated_tests && isset($repo_index['tests'][$identifier]['status']) && $repo_index['tests'][$identifier]['status'] == 'Deprecated')465 {466 continue;467 }468 if($all_versions)469 {470 $versions = $repo_index['tests'][$identifier]['versions'];471 $append_versions = true;472 }473 else474 {475 // Just get the latest version by default476 $versions = array(array_shift($repo_index['tests'][$identifier]['versions']));477 }478 foreach($versions as $version)479 {480 if($download_tests)481 {482 if(self::download_test_profile($repo . '/' . $identifier . '-' . $version) == false)483 {484 continue;485 }486 }487 $available_tests[] = $repo . '/' . $identifier . ($append_versions ? '-' . $version : null);488 }489 }490 }491 }492 $available_tests = array_unique($available_tests);493 return $available_tests;494 }495 public static function available_suites($download_suites = true)496 {497 $available_suites = array();498 foreach(self::linked_repositories() as $repo)499 {500 $repo_index = pts_openbenchmarking::read_repository_index($repo);501 if(isset($repo_index['suites']) && is_array($repo_index['suites']))502 {503 foreach(array_keys($repo_index['suites']) as $identifier)504 {505 if($download_suites && pts_network::internet_support_available())506 {507 $version = array_shift($repo_index['suites'][$identifier]['versions']);508 if(self::download_test_suite($repo . '/' . $identifier . '-' . $version) == false)509 {510 continue;511 }512 }513 $available_suites[] = $repo . '/' . $identifier;514 }515 }516 }517 return $available_suites;518 }519 public static function download_test_suite($qualified_identifier)520 {521 if(is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml'))522 {523 return true;524 }525 $file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $qualified_identifier . '.zip';526 if(pts_network::internet_support_available())527 {528 $hash_json = pts_openbenchmarking::make_openbenchmarking_request('suite_hash', array('i' => $qualified_identifier));529 $hash_json = json_decode($hash_json, true);530 $hash_check = isset($hash_json['openbenchmarking']['suite']['hash']) ? $hash_json['openbenchmarking']['suite']['hash'] : null; // should also check for ['openbenchmarking']['suite']['error'] problems531 }532 if(!is_file($file))533 {534 if(pts_network::internet_support_available())535 {536 $test_suite = pts_openbenchmarking::make_openbenchmarking_request('download_suite', array('i' => $qualified_identifier));537 if($test_suite != null && ($hash_check == null || $hash_check == sha1($test_suite)))538 {539 // save it540 file_put_contents($file, $test_suite);541 $hash_check = null;542 }543 else if(is_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') && ($hash_check == null || sha1_file('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip') == $hash_check))544 {545 copy('/var/cache/phoronix-test-suite/openbenchmarking.org/' . $qualified_identifier . '.zip', $file);546 }547 }548 if(!is_file($file) && $test_suite = self::phoromatic_server_ob_cache_request('suite', substr($qualified_identifier, 0, strpos($qualified_identifier, '/')), substr($qualified_identifier, strpos($qualified_identifier, '/') + 1)))...

Full Screen

Full Screen

pts_openbenchmarking_client.php

Source:pts_openbenchmarking_client.php Github

copy

Full Screen

...37 if(self::result_upload_supported($result_file) == false)38 {39 return false;40 }41 if(pts_network::internet_support_available() == false)42 {43 echo PHP_EOL . 'No network support available.' . PHP_EOL;44 return false;45 }46 $composite_xml = $result_file->get_xml();47 $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/';48 $upload_system_logs = false;49 if(is_dir($system_log_dir))50 {51 if(pts_config::read_bool_config('PhoronixTestSuite/Options/OpenBenchmarking/AlwaysUploadSystemLogs', 'FALSE'))52 {53 $upload_system_logs = true;54 }55 else if(isset(self::$client_settings['UploadSystemLogsByDefault']))56 {57 $upload_system_logs = self::$client_settings['UploadSystemLogsByDefault'];58 }59 else if(is_dir($system_log_dir))60 {61 if($prompts == false)62 {63 $upload_system_logs = true;64 }65 else66 {67 $upload_system_logs = pts_user_io::prompt_bool_input('Would you like to attach the system logs (lspci, dmesg, lsusb, etc) to the test result', true, 'UPLOAD_SYSTEM_LOGS');68 }69 }70 }71 $system_logs = null;72 $system_logs_hash = null;73 if($upload_system_logs)74 {75 $is_valid_log = true;76 $finfo = function_exists('finfo_open') ? finfo_open(FILEINFO_MIME_TYPE) : false;77 foreach(pts_file_io::glob($system_log_dir . '*') as $log_dir)78 {79 if($is_valid_log == false || !is_dir($log_dir))80 {81 $is_valid_log = false;82 break;83 }84 foreach(pts_file_io::glob($log_dir . '/*') as $log_file)85 {86 if(!is_file($log_file))87 {88 $is_valid_log = false;89 break;90 }91 if($finfo && substr(finfo_file($finfo, $log_file), 0, 5) != 'text/')92 {93 $is_valid_log = false;94 break;95 }96 }97 }98 if($is_valid_log)99 {100 $system_logs_zip = pts_client::create_temporary_file('.zip');101 pts_compression::zip_archive_create($system_logs_zip, $system_log_dir);102 if(filesize($system_logs_zip) < 2097152)103 {104 // If it's over 2MB, probably too big105 $system_logs = base64_encode(file_get_contents($system_logs_zip));106 $system_logs_hash = sha1($system_logs);107 }108 else109 {110 trigger_error('The systems log attachment is too large to upload to OpenBenchmarking.org.', E_USER_WARNING);111 }112 unlink($system_logs_zip);113 }114 }115 $composite_xml_hash = sha1($composite_xml);116 $composite_xml_type = 'composite_xml';117 // Compress the result file XML if it's big118 if(isset($composite_xml[50000]) && function_exists('gzdeflate'))119 {120 $composite_xml_gz = gzdeflate($composite_xml);121 if($composite_xml_gz != false)122 {123 $composite_xml = $composite_xml_gz;124 $composite_xml_type = 'composite_xml_gz';125 }126 }127 $to_post = array(128 $composite_xml_type => base64_encode($composite_xml),129 'composite_xml_hash' => $composite_xml_hash,130 'local_file_name' => $local_file_name,131 'this_results_identifier' => $results_identifier,132 'system_logs_zip' => $system_logs,133 'system_logs_hash' => $system_logs_hash134 );135 if(isset(self::$client_settings['ResultUploadsDefaultDisplayStatus']) && is_numeric(self::$client_settings['ResultUploadsDefaultDisplayStatus']))136 {137 $to_post['display_status'] = self::$client_settings['ResultUploadsDefaultDisplayStatus'];138 }139 $json_response = pts_openbenchmarking::make_openbenchmarking_request('upload_test_result', $to_post);140 $json_response = json_decode($json_response, true);141 if(!is_array($json_response))142 {143 trigger_error('Unhandled Exception', E_USER_ERROR);144 return false;145 }146 if(isset($json_response['openbenchmarking']['upload']['error']))147 {148 trigger_error($json_response['openbenchmarking']['upload']['error'], E_USER_ERROR);149 }150 if(isset($json_response['openbenchmarking']['upload']['url']))151 {152 echo PHP_EOL . 'Results Uploaded To: ' . $json_response['openbenchmarking']['upload']['url'] . PHP_EOL;153 pts_module_manager::module_process('__event_openbenchmarking_upload', $json_response);154 }155 //$json['openbenchmarking']['upload']['id']156 if(isset(self::$client_settings['RemoveLocalResultsOnUpload']) && self::$client_settings['RemoveLocalResultsOnUpload'] && $local_file_name != null)157 {158 pts_client::remove_saved_result_file($local_file_name);159 }160 if($return_json_data)161 {162 return isset($json_response['openbenchmarking']['upload']) ? $json_response['openbenchmarking']['upload'] : false;163 }164 return isset($json_response['openbenchmarking']['upload']['url']) ? $json_response['openbenchmarking']['upload']['url'] : false;165 }166 public static function recently_updated_tests($limit = -1)167 {168 $available_tests = array();169 foreach(pts_openbenchmarking::linked_repositories() as $repo)170 {171 $repo_index = pts_openbenchmarking::read_repository_index($repo);172 if(isset($repo_index['tests']) && is_array($repo_index['tests']))173 {174 foreach(array_keys($repo_index['tests']) as $identifier)175 {176 if($repo_index['tests'][$identifier]['title'] == null)177 {178 continue;179 }180 $version = array_shift($repo_index['tests'][$identifier]['versions']);181 $update_time = $repo_index['tests'][$identifier]['last_updated'];182 $available_tests[$update_time] = $repo . '/' . $identifier . '-' . $version;183 }184 }185 }186 krsort($available_tests);187 if($limit > 0)188 {189 $available_tests = array_slice($available_tests, 0, $limit);190 }191 return $available_tests;192 }193 public static function popular_tests($limit = -1, $test_type = null)194 {195 $available_tests = array();196 foreach(pts_openbenchmarking::linked_repositories() as $repo)197 {198 $repo_index = pts_openbenchmarking::read_repository_index($repo);199 if(isset($repo_index['tests']) && is_array($repo_index['tests']))200 {201 foreach(array_keys($repo_index['tests']) as $identifier)202 {203 if($repo_index['tests'][$identifier]['title'] == null)204 {205 continue;206 }207 $popularity = $repo_index['tests'][$identifier]['popularity'];208 if($popularity < 1 || ($test_type != null && $repo_index['tests'][$identifier]['test_type'] != $test_type))209 {210 continue;211 }212 $available_tests[$repo . '/' . $identifier] = $popularity;213 }214 }215 }216 asort($available_tests);217 if($limit > 0)218 {219 $available_tests = array_slice($available_tests, 0, $limit);220 }221 return array_keys($available_tests);222 }223 public static function search_tests($search, $test_titles_only = true)224 {225 $matching_tests = array();226 foreach(pts_openbenchmarking::linked_repositories() as $repo)227 {228 $repo_index = pts_openbenchmarking::read_repository_index($repo);229 if(isset($repo_index['tests']) && is_array($repo_index['tests']))230 {231 foreach(array_keys($repo_index['tests']) as $identifier)232 {233 if(stripos($identifier, $search) !== false || stripos($repo_index['tests'][$identifier]['title'], $search) !== false)234 {235 $matching_tests[] = $repo . '/' . $identifier;236 }237 else if($test_titles_only == false && (stripos(implode(' ', $repo_index['tests'][$identifier]['internal_tags']), $search) !== false || stripos($repo_index['tests'][$identifier]['test_type'], $search) !== false || stripos($repo_index['tests'][$identifier]['description'], $search) !== false))238 {239 $matching_tests[] = $repo . '/' . $identifier;240 }241 }242 }243 }244 return $matching_tests;245 }246 public static function tests_available()247 {248 $test_count = 0;249 foreach(pts_openbenchmarking::linked_repositories() as $repo)250 {251 $repo_index = pts_openbenchmarking::read_repository_index($repo);252 if(isset($repo_index['tests']) && is_array($repo_index['tests']))253 {254 $test_count += count($repo_index['tests']);255 }256 }257 return $test_count;258 }259 public static function init_account($openbenchmarking, $settings)260 {261 if(isset($openbenchmarking['user_name']) && isset($openbenchmarking['communication_id']) && isset($openbenchmarking['sav']))262 {263 if(IS_FIRST_RUN_TODAY && pts_network::internet_support_available())264 {265 // Might as well make sure OpenBenchmarking.org account has the latest system info266 // But don't do it everytime to preserve bandwidth267 $openbenchmarking['s_s'] = base64_encode(phodevi::system_software(true));268 $openbenchmarking['s_h'] = base64_encode(phodevi::system_hardware(true));269 $return_state = pts_openbenchmarking::make_openbenchmarking_request('account_verify', $openbenchmarking);270 $json = json_decode($return_state, true);271 if(isset($json['openbenchmarking']['account']['valid']))272 {273 // The account is valid274 self::$openbenchmarking_account = $openbenchmarking;275 self::$client_settings = $json['openbenchmarking']['account']['settings'];276 pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'openbenchmarking_account_settings', $json['openbenchmarking']['account']['settings']);277 }278 else279 {280 pts_storage_object::set_in_file(PTS_CORE_STORAGE, 'openbenchmarking', false);281 trigger_error('Invalid OpenBenchmarking.org account supplied, please re-login.', E_USER_ERROR);282 }283 }284 else285 {286 self::$openbenchmarking_account = $openbenchmarking;287 self::$client_settings = $settings;288 }289 }290 }291 public static function get_openbenchmarking_account()292 {293 return self::$openbenchmarking_account;294 }295 public static function auto_upload_results()296 {297 return isset(self::$client_settings['AutoUploadResults']) && self::$client_settings['AutoUploadResults'];298 }299 public static function override_client_setting($key, $value)300 {301 self::$client_settings[$key] = $value;302 }303 protected static function result_upload_supported(&$result_file)304 {305 foreach($result_file->get_result_objects() as $result_object)306 {307 $test_profile = new pts_test_profile($result_object->test_profile->get_identifier());308 if($test_profile->allow_results_sharing() == false)309 {310 echo PHP_EOL . $result_object->test_profile->get_identifier() . ' does not allow test results to be uploaded.' . PHP_EOL . PHP_EOL;311 return false;312 }313 }314 return true;315 }316 public static function read_repository_test_profile_attribute($test_profile, $attribute)317 {318 list($repo, $tp) = explode('/', $test_profile);319 $tp = substr($tp, 0, strrpos($tp, '-'));320 $repo_index = pts_openbenchmarking::read_repository_index($repo);321 return isset($repo_index['tests'][$tp][$attribute]) ? $repo_index['tests'][$tp][$attribute] : null;322 }323 public static function popular_openbenchmarking_results()324 {325 $index_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . 'popular.results';326 if(!is_file($index_file) || filemtime($index_file) < (time() - 1800))327 {328 // Refresh the repository change-log just once a day should be fine329 $server_index = pts_openbenchmarking::make_openbenchmarking_request('interesting_results');330 if(json_decode($server_index) != false)331 {332 file_put_contents($index_file, $server_index);333 }334 }335 $results = is_file($index_file) ? json_decode(file_get_contents($index_file), true) : false;336 return $results ? $results['results'] : false;337 }338 public static function fetch_repository_changelog($repo_name)339 {340 $index_file = PTS_OPENBENCHMARKING_SCRATCH_PATH . $repo_name . '.changes';341 if(!is_file($index_file) || filemtime($index_file) < (time() - 86400))342 {343 // Refresh the repository change-log just once a day should be fine344 $server_index = pts_openbenchmarking::make_openbenchmarking_request('repo_changes', array('repo' => $repo_name));345 if(json_decode($server_index) != false)346 {347 file_put_contents($index_file, $server_index);348 }349 }350 return is_file($index_file) ? json_decode(file_get_contents($index_file), true) : false;351 }352 public static function user_name()353 {354 return isset(self::$openbenchmarking_account['user_name']) ? self::$openbenchmarking_account['user_name'] : false;355 }356 public static function upload_usage_data($task, $data)357 {358 if(!pts_network::internet_support_available())359 {360 return false;361 }362 switch($task)363 {364 case 'test_install':365 list($test_install, $time_elapsed) = $data;366 $upload_data = array('test_identifier' => $test_install->test_profile->get_identifier(), 'test_version' => $test_install->test_profile->get_test_profile_version(), 'elapsed_time' => $time_elapsed);367 pts_network::http_upload_via_post(pts_openbenchmarking::openbenchmarking_host() . 'extern/statistics/report-test-install.php', $upload_data);368 break;369 case 'test_complete':370 list($test_result, $time_elapsed) = $data;371 $upload_data = array('test_identifier' => $test_result->test_profile->get_identifier(), 'test_version' => $test_result->test_profile->get_test_profile_version(), 'elapsed_time' => $time_elapsed);372 pts_network::http_upload_via_post(pts_openbenchmarking::openbenchmarking_host() . 'extern/statistics/report-test-completion.php', $upload_data);373 break;374 case 'test_install_failure':375 list($test_install, $error) = $data;376 $upload_data = array('test_identifier' => $test_install->test_profile->get_identifier(), 'error' => $error, 'os' => phodevi::read_property('system', 'vendor-identifier'));377 pts_network::http_upload_via_post(pts_openbenchmarking::openbenchmarking_host() . 'extern/statistics/report-test-install-failure.php', $upload_data);378 break;379 }380 }381 public static function request_gsid()382 {383 if(!pts_network::internet_support_available())384 {385 return false;386 }387 $payload = array(388 'client_version' => PTS_VERSION,389 'client_os' => phodevi::read_property('system', 'vendor-identifier')390 );391 $json = pts_openbenchmarking::make_openbenchmarking_request('request_gsid', $payload);392 $json = json_decode($json, true);393 return isset($json['openbenchmarking']['gsid']) ? $json['openbenchmarking']['gsid'] : false;394 }395 public static function update_gsid()396 {397 if(!pts_network::internet_support_available())398 {399 return false;400 }401 $payload = array(402 'client_version' => PTS_VERSION,403 'client_os' => phodevi::read_property('system', 'vendor-identifier')404 );405 pts_openbenchmarking::make_openbenchmarking_request('update_gsid', $payload);406 }407 public static function retrieve_gsid()408 {409 if(!pts_network::internet_support_available())410 {411 return false;412 }413 // If the GSID_E and GSID_P are not known due to being from an old client414 $json = pts_openbenchmarking::make_openbenchmarking_request('retrieve_gsid', array());415 $json = json_decode($json, true);416 return isset($json['openbenchmarking']['gsid']) ? $json['openbenchmarking']['gsid'] : false;417 }418}419?>...

Full Screen

Full Screen

internet_support_available

Using AI Code Generation

copy

Full Screen

1$internet_support_available = pts_network::internet_support_available();2if($internet_support_available == true)3{4echo 'Internet connection is available';5}6{7echo 'Internet connection is not available';8}

Full Screen

Full Screen

internet_support_available

Using AI Code Generation

copy

Full Screen

1require_once('pts_network.php');2if(pts_network::internet_support_available())3{4echo "Internet support is available";5}6{7echo "Internet support is not available";8}

Full Screen

Full Screen

internet_support_available

Using AI Code Generation

copy

Full Screen

1require_once('pts_network.php');2$pts_network = new pts_network();3$internet_support_available = $pts_network->internet_support_available();4if($internet_support_available == true){5echo "Internet support available";6}else{7echo "Internet support not available";8}

Full Screen

Full Screen

internet_support_available

Using AI Code Generation

copy

Full Screen

1include_once "pts_network.php";2$network = new pts_network();3if ($network->internet_support_available()) {4 echo "Internet support available";5} else {6 echo "Internet support not available";7}

Full Screen

Full Screen

internet_support_available

Using AI Code Generation

copy

Full Screen

1require_once('pts_network.php');2$net = new pts_network();3if($net->internet_support_available())4{5echo "Internet is available";6}7{8echo "Internet is not available";9}

Full Screen

Full Screen

internet_support_available

Using AI Code Generation

copy

Full Screen

1$internet_support_available = pts_network::internet_support_available();2if($internet_support_available)3{4echo "Internet is available";5}6{7echo "Internet is not available";8}9$internet_support_available = pts_network::internet_support_available();10if($internet_support_available)11{12echo "Internet is available";13}14{15echo "Internet is not available";16}

Full Screen

Full Screen

internet_support_available

Using AI Code Generation

copy

Full Screen

1{2 echo 'Internet is available';3}4{5 echo 'Internet is not available';6}

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.

Run Phoronix-test-suite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger internet_support_available code on LambdaTest Cloud Grid

Execute automation tests with internet_support_available on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful