Best Phoronix-test-suite code snippet using pts_openbenchmarking.phoromatic_server_ob_cache_request
pts_openbenchmarking.php
Source:pts_openbenchmarking.php  
...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)))549			{550				if($b64 = base64_decode($test_suite))551				{552					$test_suite = $b64;553				}554				file_put_contents($file, $test_suite);555			}556			if(PTS_IS_CLIENT && !is_file($file))557			{558				trigger_error('Network support is needed to obtain ' . $qualified_identifier . ' data.' . PHP_EOL, E_USER_ERROR);559				return false;560			}561		}562		if(!is_file(PTS_TEST_SUITE_PATH . $qualified_identifier . '/suite-definition.xml') && is_file($file) && ($hash_check == null || (is_file($file) && sha1_file($file) == $hash_check)))...phoromatic_server_ob_cache_request
Using AI Code Generation
1$ob = new pts_openbenchmarking();2$ob = new pts_openbenchmarking();3$ob = new pts_openbenchmarking();4$ob = new pts_openbenchmarking();5$ob = new pts_openbenchmarking();6$ob = new pts_openbenchmarking();7$ob = new pts_openbenchmarking();phoromatic_server_ob_cache_request
Using AI Code Generation
1require_once('pts-core/pts_openbenchmarking.php');2$ob = new pts_openbenchmarking();3$ob->phoromatic_server_ob_cache_request('2.php', $_GET['test_profile'], $_GET['test_profile_version']);4require_once('pts-core/pts_openbenchmarking.php');5$ob = new pts_openbenchmarking();6$ob->phoromatic_server_ob_cache_request('3.php', $_GET['test_profile'], $_GET['test_profile_version']);7require_once('pts-core/pts_openbenchmarking.php');8$ob = new pts_openbenchmarking();9$ob->phoromatic_server_ob_cache_request('4.php', $_GET['test_profile'], $_GET['test_profile_version']);10require_once('pts-core/pts_openbenchmarking.php');11$ob = new pts_openbenchmarking();12$ob->phoromatic_server_ob_cache_request('5.php', $_GET['test_profile'], $_GET['test_profile_version']);13require_once('pts-core/pts_openbenchmarking.php');14$ob = new pts_openbenchmarking();15$ob->phoromatic_server_ob_cache_request('6.php', $_GET['test_profile'], $_GET['test_profile_version']);16require_once('pts-core/pts_openbenchmarking.php');17$ob = new pts_openbenchmarking();18$ob->phoromatic_server_ob_cache_request('7.php', $_GET['test_profile'], $_GET['test_profile_version']);19require_once('pts-core/pts_openbenchmarking.php');20$ob = new pts_openbenchmarking();phoromatic_server_ob_cache_request
Using AI Code Generation
1include_once(PTS_CORE_STATIC_PATH . 'openbenchmarking.php');2$result = pts_openbenchmarking::phoromatic_server_ob_cache_request('2.php');3if ($result != false)4{5echo $result;6}7{8echo $result;9pts_openbenchmarking::phoromatic_server_ob_cache_save('2.php', $result);10}11include_once(PTS_CORE_STATIC_PATH . 'openbenchmarking.php');12$result = pts_openbenchmarking::phoromatic_server_ob_cache_request('3.php');13if ($result != false)14{15echo $result;16}17{18echo $result;19pts_openbenchmarking::phoromatic_server_ob_cache_save('3.php', $result);20}21include_once(PTS_CORE_STATIC_PATH . 'openbenchmarking.php');22$result = pts_openbenchmarking::phoromatic_server_ob_cache_request('4.php');phoromatic_server_ob_cache_request
Using AI Code Generation
1require_once('pts_openbenchmarking.php');2$test_name = 'test_name';3$test_version = 'test_version';4$test_profile = 'test_profile';5$test_identifier = 'test_identifier';6$test_arguments = 'test_arguments';7$test_run_count = 'test_run_count';8$test_run_time = 'test_run_time';9$test_run_trigger = 'test_run_trigger';10$system_name = 'system_name';11$system_version = 'system_version';12$system_architecture = 'system_architecture';13$system_kernel = 'system_kernel';14$system_processor = 'system_processor';15$system_memory = 'system_memory';16$system_gpu = 'system_gpu';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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with phoromatic_server_ob_cache_request on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!
