Home  >  Article  >  Backend Development  >  Reading efficiency of php text files_PHP tutorial

Reading efficiency of php text files_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:21:111178browse

The homepage is about 3KB and was tested locally

Copy the code The code is as follows:

file_get_contents('shadow.xml ');

Took 0.0003 seconds
Copy code The code is as follows:

$indexFile = fopen('shadow.xml', 'r');while ( !feof($indexFile)) fgetc( $indexFile);

Took 0.026 seconds
Copy code The code is as follows:

$indexFile = fopen('shadow.xml', 'r');fread($indexFile, 10000);

It took 0.0003 seconds
The difference is nearly 100 times! ! It’s really unexpected

I guess all the time is lost in the while loop or something.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324988.htmlTechArticleThe homepage is about 3KB. The copied code for local testing is as follows: file_get_contents('shadow.xml'); consumption Copy the code in 0.0003 seconds. The code is as follows: $indexFile = fopen('shadow.xml', 'r'...
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