Best Phoronix-test-suite code snippet using pts_network.stream_context_create
pts_network.php
Source:pts_network.php
...42 if(!pts_network::network_support_available())43 {44 return false;45 }46 $stream_context = pts_network::stream_context_create(null, $override_proxy, $override_proxy_port, $override_proxy_user, $override_proxy_pw, $http_timeout);47 $contents = pts_file_io::file_get_contents($url, 0, $stream_context);48 return $contents;49 }50 public static function can_reach_phoronix_test_suite_com()51 {52 return pts_network::http_get_contents('http://www.phoronix-test-suite.com/PTS') == 'PTS';53 }54 public static function can_reach_openbenchmarking_org()55 {56 return pts_network::http_get_contents('http://openbenchmarking.org/PTS') == 'PTS';57 }58 public static function can_reach_phoronix_net()59 {60 return pts_network::http_get_contents('http://phoronix.net/PTS') == 'PTS';61 }62 public static function http_upload_via_post($url, $to_post_data, $supports_proxy = true)63 {64 if(!pts_network::network_support_available())65 {66 return false;67 }68 $http_parameters = array('http' => array('method' => 'POST', 'content' => http_build_query($to_post_data)));69 if($supports_proxy)70 {71 $stream_context = pts_network::stream_context_create($http_parameters);72 }73 else74 {75 $stream_context = pts_network::stream_context_create($http_parameters, false, -1, -1);76 }77 $opened_url = fopen($url, 'rb', false, $stream_context);78 $response = $opened_url ? stream_get_contents($opened_url) : false;79 // var_dump($url); var_dump($to_post_data);80 return $response;81 }82 public static function download_file($download, $to)83 {84 if(!pts_network::network_support_available())85 {86 return false;87 }88 if(strpos($download, '://') === false)89 {90 $download = 'http://' . $download;91 }92 else if(getenv('NO_HTTPS') != false)93 {94 // On some platforms like DragonFly 4.2 ran into problem of all HTTPS downloads failing95 $download = str_replace('https://', 'http://', $download);96 }97 if(PTS_IS_CLIENT && strpos(phodevi::read_property('system', 'operating-system'), ' 7') === false && function_exists('curl_init') && stripos(PTS_PHP_VERSION, 'hiphop') === false)98 {99 // XXX: RHEL/EL 7.6 PHP packages introduced a segv when using CURL... Until that's resolved, just blacklist " 7"100 // as unknown when it will be fixed, but at least there is non-CURL codepath supported fine101 // " 7" is a bit liberal but also hard due to various EL7 downstreams102 // XXX: Facebook HipHop HHVM currently seems to have problems with PHP CURL103 $return_state = pts_network::curl_download($download, $to);104 }105 else106 {107 $return_state = pts_network::stream_download($download, $to);108 }109 //echo '\nPHP CURL must either be installed or you must adjust your PHP settings file to support opening FTP/HTTP streams.\n';110 //return false;111 if($return_state == true)112 {113 pts_client::$display->test_install_progress_completed();114 }115 }116 public static function curl_download($download, $download_to, $download_port_number = false)117 {118 if(!function_exists('curl_init'))119 {120 return false;121 }122 // XXX: with curl_multi_init we could do multiple downloads at once...123 $cr = curl_init();124 $fh = fopen($download_to, 'w');125 curl_setopt($cr, CURLOPT_FILE, $fh);126 curl_setopt($cr, CURLOPT_URL, $download);127 curl_setopt($cr, CURLOPT_HEADER, false);128 curl_setopt($cr, CURLOPT_FOLLOWLOCATION, true);129 curl_setopt($cr, CURLOPT_CONNECTTIMEOUT, self::$network_timeout);130 curl_setopt($cr, CURLOPT_BUFFERSIZE, 64000);131 curl_setopt($cr, CURLOPT_USERAGENT, pts_core::codename(true));132 curl_setopt($cr, CURLOPT_CAPATH, PTS_CORE_STATIC_PATH . 'certificates/');133 curl_setopt($cr, CURLOPT_SSL_VERIFYPEER, false);134 if($download_port_number)135 {136 curl_setopt($cr, CURLOPT_PORT, $port);137 }138 if(stripos($download, 'sourceforge') === false)139 {140 // Setting the referer causes problems for SourceForge downloads141 curl_setopt($cr, CURLOPT_REFERER, 'http://www.phoronix-test-suite.com/');142 }143 if(strpos($download, 'https://openbenchmarking.org/') !== false)144 {145 curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, 2);146 curl_setopt($cr, CURLOPT_CAINFO, PTS_CORE_STATIC_PATH . 'certificates/openbenchmarking-server.pem');147 }148 else if(strpos($download, 'https://www.phoromatic.com/') !== false)149 {150 curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, 2);151 curl_setopt($cr, CURLOPT_CAINFO, PTS_CORE_STATIC_PATH . 'certificates/phoromatic-com.pem');152 }153 if(defined('CURLOPT_PROGRESSFUNCTION'))154 {155 // CURLOPT_PROGRESSFUNCTION only seems to work with PHP 5.3+, but is not working with HipHop HHVM ~2.0.1156 curl_setopt($cr, CURLOPT_NOPROGRESS, false);157 curl_setopt($cr, CURLOPT_PROGRESSFUNCTION, array('pts_network', 'curl_status_callback'));158 }159 if(self::$network_proxy)160 {161 curl_setopt($cr, CURLOPT_PROXY, self::$network_proxy['proxy']);162 if(!empty(self::$network_proxy['user']))163 {164 curl_setopt($cr, CURLOPT_USERPWD, self::$network_proxy['user'] . ':' . self::$network_proxy['password']);165 }166 }167 curl_exec($cr);168 curl_close($cr);169 fclose($fh);170 return true;171 }172 public static function stream_download($download, $download_to, $stream_context_parameters = null, $callback_function = array('pts_network', 'stream_status_callback'))173 {174 $stream_context = pts_network::stream_context_create($stream_context_parameters);175 if(function_exists('stream_context_set_params'))176 {177 // HHVM 2.1 doesn't have stream_context_set_params()178 stream_context_set_params($stream_context, array('notification' => $callback_function));179 }180 /*181 if(strpos($download, 'https://openbenchmarking.org/') !== false)182 {183 stream_context_set_option($stream_context, 'ssl', 'local_cert', PTS_CORE_STATIC_PATH . 'certificates/openbenchmarking-server.pem');184 }185 else if(strpos($download, 'https://www.phoromatic.com/') !== false)186 {187 stream_context_set_option($stream_context, 'ssl', 'local_cert', PTS_CORE_STATIC_PATH . 'certificates/phoromatic-com.pem');188 }189 */190 $file_pointer = @fopen($download, 'r', false, $stream_context);191 if(is_resource($file_pointer) && file_put_contents($download_to, $file_pointer))192 {193 return true;194 }195 return false;196 }197 public static function stream_context_create($parameters = null, $proxy_address = false, $proxy_port = false, $proxy_user = false, $proxy_password = false, $http_timeout = -1)198 {199 if(!is_array($parameters))200 {201 $parameters = array();202 }203 $parameters['ssl']['verify_peer'] = false;204 $parameters['ssl']['verify_peer_name'] = false;205 if($proxy_address == false && $proxy_port == false && self::$network_proxy)206 {207 $proxy_address = self::$network_proxy['address'];208 $proxy_port = self::$network_proxy['port'];209 $proxy_user = self::$network_proxy['user'];210 $proxy_password = self::$network_proxy['password'];211 }212 if($proxy_address != false && $proxy_port != false && is_numeric($proxy_port) && $proxy_port > 1)213 {214 $parameters['http']['proxy'] = 'tcp://' . $proxy_address . ':' . $proxy_port;215 $parameters['http']['request_fulluri'] = true;216 }217 if(is_numeric($http_timeout) && $http_timeout > 1)218 {219 $parameters['http']['timeout'] = $http_timeout;220 }221 else222 {223 $parameters['http']['timeout'] = self::$network_timeout;224 }225 $parameters['http']['user_agent'] = pts_core::codename(true);226 if($proxy_user != false && !empty($proxy_user))227 {228 $password = pts_strings::hex_to_str($proxy_password);229 $parameters['http']['header'] = 'Proxy-Authorization: Basic ' . base64_encode($proxy_user . ':' . $password);230 }231 else232 {233 $parameters['http']['header'] = "Content-Type: application/x-www-form-urlencoded\r\n";234 }235 $stream_context = stream_context_create($parameters);236 return $stream_context;237 }238 //239 // Callback Functions240 //241 public static function stream_status_callback($notification_code, $arg1, $message, $message_code, $downloaded, $download_size)242 {243 static $filesize = 0;244 static $last_float = -1;245 switch($notification_code)246 {247 case STREAM_NOTIFY_FILE_SIZE_IS:248 $filesize = $download_size;249 break;...
stream_context_create
Using AI Code Generation
1$context = pts_network::stream_context_create();2$context['http']['method'] = 'POST';3$context['http']['header'] = 'Content-type: application/x-www-form-urlencoded';4$context['http']['content'] = http_build_query(array('username' => 'test', 'password' => 'test'));5echo $contents;6$context = pts_network::stream_context_create();7$context['http']['method'] = 'POST';8$context['http']['header'] = 'Content-type: application/x-www-form-urlencoded';9$context['http']['content'] = http_build_query(array('username' => 'test', 'password' => 'test'));10echo $contents;11$context = pts_network::stream_context_create();12$context['http']['method'] = 'POST';13$context['http']['header'] = 'Content-type: application/x-www-form-urlencoded';14$context['http']['content'] = http_build_query(array('username' => 'test', 'password' => 'test'));15echo $contents;16$context = pts_network::stream_context_create();17$context['http']['method'] = 'POST';
stream_context_create
Using AI Code Generation
1$pts = new pts_network();2$opts = array('http' =>3 array(4);5$context = stream_context_create($opts);6$contents = stream_get_contents($fp);7print_r($contents);8$pts = new pts_network();9$opts = array('http' =>10 array(11);12$context = stream_context_create($opts);13$contents = stream_get_contents($fp);14print_r($contents);15$pts = new pts_network();16$opts = array('http' =>17 array(18);19$context = stream_context_create($opts);20$contents = stream_get_contents($fp);21print_r($contents);22$pts = new pts_network();23$opts = array('http' =>24 array(
stream_context_create
Using AI Code Generation
1$pts_network = new pts_network();2$context = $pts_network->stream_context_create();3$pts_network = new pts_network();4$context = $pts_network->stream_context_create();5$pts_network = new pts_network();6$context = $pts_network->stream_context_create();7$pts_network = new pts_network();8$context = $pts_network->stream_context_create();9$pts_network = new pts_network();10$context = $pts_network->stream_context_create();11$pts_network = new pts_network();12$context = $pts_network->stream_context_create();13$pts_network = new pts_network();14$context = $pts_network->stream_context_create();15$pts_network = new pts_network();16$context = $pts_network->stream_context_create();17$pts_network = new pts_network();18$context = $pts_network->stream_context_create();
stream_context_create
Using AI Code Generation
1require_once('pts_network.php');2$pts_network = new pts_network();3$stream_context = $pts_network->stream_context_create(array('http'=>array('method'=>'GET','header'=>'Accept-language: en\r4User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0\r5')));6echo $stream;7require_once('pts_network.php');8$pts_network = new pts_network();9echo $stream;10require_once('pts_network.php');11$pts_network = new pts_network();12$stream_context = $pts_network->stream_context_create(array('http'=>array('method'=>'GET','header'=>'Accept-language: en\r13User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0\r14')));15echo $stream;
stream_context_create
Using AI Code Generation
1$network = new pts_network();2$context = $network->stream_context_create($opts);3while($line = fgets($fp))4{5 echo $line;6}7fclose($fp);8$network = new pts_network();9$context = $network->stream_context_create($opts);10while($line = fgets($fp))11{12 echo $line;13}14fclose($fp);15$network = new pts_network();16$context = $network->stream_context_create($opts);17while($line = fgets($fp))18{19 echo $line;20}21fclose($fp);22$network = new pts_network();23$context = $network->stream_context_create($opts);24while($line = fgets($fp))25{26 echo $line;27}28fclose($fp);29$network = new pts_network();30$context = $network->stream_context_create($opts);31while($line = fgets($fp))32{33 echo $line;34}35fclose($fp);36$network = new pts_network();37$context = $network->stream_context_create($opts);38while($line = fgets($fp))39{40 echo $line;41}42fclose($fp);43$network = new pts_network();44$context = $network->stream_context_create($opts);
stream_context_create
Using AI Code Generation
1$context = stream_context_create($opts);2if (!$fp) {3 echo "Error opening file!";4 exit;5}6while (!feof($fp)) {7 echo fgets($fp, 1024);8}9fclose($fp);10$context = stream_context_create($opts);11if (!$fp) {12 echo "Error opening file!";13 exit;14}15while (!feof($fp)) {16 echo fgets($fp, 1024);17}18fclose($fp);19$context = stream_context_create($opts);20if (!$fp) {21 echo "Error opening file!";22 exit;23}24while (!feof($fp)) {25 echo fgets($fp, 1024);26}27fclose($fp);28$context = stream_context_create($opts);29if (!$fp) {30 echo "Error opening file!";31 exit;32}33while (!feof($fp)) {34 echo fgets($fp, 1024);35}36fclose($fp);37$context = stream_context_create($opts);38if (!$fp) {39 echo "Error opening file!";40 exit;41}42while (!feof($fp)) {43 echo fgets($fp, 1024);44}45fclose($fp);46$context = stream_context_create($opts);47if (!$fp) {48 echo "Error opening file!";49 exit;50}51while (!feof($fp)) {52 echo fgets($fp, 1024);53}54fclose($fp);
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 stream_context_create 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!!