dio_open
(PHP 4 >= 4.2.0, PHP 5 < 5.1.0)
dio_open — 在 C 库输入/输出流函数允许的更低级别打开(必要时创建)文件
参数
返回值
文件描述符,错误时是 false
。
示例
示例 #1 打开文件描述符
<?php
$fd = dio_open('/dev/ttyS0', O_RDWR | O_NOCTTY | O_NONBLOCK);
dio_close($fd);
?>
+添加备注
用户贡献的备注 3 notes
j at pureftpd dot org ¶
20 years ago
Please note that dio_open()/dio_write()/dio_close() is *faster* than fopen()/fwrite()/fclose() for files.
fwrite() has to manage a 8k buffer, while dio_write() just issue a single write(). The end result is less system calls and less memory access.
Also, giving the full size to write() as with dio_write() let filesystems properly use preallocation in order to avoid fragmentation.
Marius Karthaus ¶
14 years ago
One of the prominent reasons to use direct IO, is for it's ability to do actual direct IO, bypassing the operating system cache and getting the data from the disk directly.
The flag to do that (O_DIRECT) is missing from the documentation above. Maybe for good reasons, because this type of IO only works on blockdevices, not on files, and should only be used if you are **really** sure what you are doing.