|
发表于 2007 年 7 月 20 日 14:37:25
|
显示全部楼层
测试代码
- <?php
- set_time_limit(0);
- function mtime() {
- list($usec, $sec) = explode(' ', microtime());
- return ((float)$usec + (float)$sec);
- }
- $time_begin = mtime();
- for ($i = 0; $i < 50; $i++) {
- $data = '';
- $data = file_get_contents('http://www.baidu.com');
- }
- $time_end = mtime();
- echo 'file_get_contents: ', $time_end - $time_begin, '<br />';
- $time_begin = mtime();
- for ($i = 0; $i < 50; $i++) {
- $data = '';
- $data = file('http://www.baidu.com');
- }
- $time_end = mtime();
- echo 'file: ', $time_end - $time_begin, '<br />';
- $time_begin = mtime();
- for ($i = 0; $i < 50; $i++) {
- $data = '';
- $fp = fsockopen('www.baidu.com', 80);
- $out = "GET / HTTP/1.1\r\n";
- $out .= "Host: [url]www.baidu.com[/url]\r\n";
- $out .= "Connection: Close\r\n\r\n";
- fwrite($fp, $out);
- while (!feof($fp)) {
- $data .= fgets($fp, 128);
- }
- fclose($fp);
- }
- $time_end = mtime();
- echo 'fsockopen: ', $time_end - $time_begin, '<br />';
复制代码
第一次
file_get_contents: 12.467694997787
file: 12.547880887985
fsockopen: 9.6251020431519
第二次
file_get_contents: 10.840023040771
file: 12.598785877228
fsockopen: 9.7779731750488
第三次
file_get_contents: 9.7077579498291
file: 9.5748469829559
fsockopen: 12.533878087997
第四次
file_get_contents: 10.059661149979
file: 9.4984700679779
fsockopen: 9.7483789920807
第五次
file_get_contents: 12.61283493042
file: 10.825304985046
fsockopen: 9.6883759498596 |
|