Home > Backend Development > PHP Tutorial > php 文本文件的读取效率_PHP

php 文本文件的读取效率_PHP

WBOY
Release: 2016-06-01 12:12:59
Original
959 people have browsed it

首页大概3KB,是在本地测试的

复制代码 代码如下:
file_get_contents('shadow.xml');

耗时 0.0003 秒
复制代码 代码如下:
$indexFile = fopen('shadow.xml', 'r');while ( !feof($indexFile)) fgetc( $indexFile);

耗时 0.026 秒
复制代码 代码如下:
$indexFile = fopen('shadow.xml', 'r');fread($indexFile, 10000);

耗时 0.0003秒
相差将近 100 倍!! 还真是出乎意料

我估摸着时间怕都牺牲在while循环上还是怎的

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template