Home >Backend Development >PHP Tutorial >Source-php-request-1

Source-php-request-1

WBOY
WBOYOriginal
2016-06-23 13:31:09876browse

我习惯使用Fiddler来发送请求头,因为Composer太好用了。但是有时候循环个1M次,总不能单击1M次吧。当然ab,Tsung都可以实现。有时候程序控制会更方便,所以写了这些:供以后使用(有一部分没有完善)

<?php //http://api.k780.com:88/?app=weather.today&weaid=1&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=xml $startTime = microtime(true); for($i = 1; $i < 20; $i++ ){ if($i % 1 == 0){ $j = $i % 10; echo "0"; } $host = "www.cnblogs.com"; $handle = fsockopen($host, 80, $errorCode, $errorMsg, 10); if(!$handle){ echo "error"; return; } //使用数组进行构造一个请求头 $headerArr = array( ); $header = "GET /jiaxu/p/4599675.html HTTP/1.1\r\n"; $header .= "Host: www.cnblogs.com\r\n"; $header .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0\r\n"; $header .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"; $header .= "Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3\r\n"; $header .= "Cookie: _ga=GA1.3.80880395.1436242846\r\n"; $header .= "Connection: keep-alive\r\n"; $header .= "If-Modified-Since: Tue, 07 Jul 2015 06:05:{$i} GMT\r\n"; $header .= "X-Forwarded-For: 192.168.2.{$j}02\r\n\r\n"; fwrite($handle, $header); $line = ""; while(!feof($handle)){ $line .= fgets($handle); } //echo $line; fclose($handle); } $endTime = microtime(true); echo $errorCode,":"; $total = $endTime - $startTime; echo $total; ?>

版权声明:本文为博主原创文章,未经博主允许不得转载。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Source-php-request-2Next article:jQuery回车登陆不会写