• PHP Video Tutorials

PHP - Direct I/O open() Function



dio_open() function can open a new filename file with specified flags permission and mode creation permission.

Syntax

resource dio_open( string filename, int flags [, int mode] )

dio_open() function function can open a file and return a new file descriptor for it, or -1 if an error occurs. If "flags" is O_CREAT, an optional third parameter mode can set a file mode(permission to create).

The flags parameter can be one of O_RDONLY (open a file for reading), O_WRONLY (open a file for writing), and O_RDWR (open a file for reading and writing).

The flags parameter may also contain combinations of the following flags −

  • O_CREAT (create a file if it does not exist).

  • O_EXCL (when both O_CREAT and O_EXCL are set, dio_open() can fail if the file already exists).

  • O_TRUNC (if the file exists, and is open for writing, it is truncated to zero sizes).

  • O_APPEND ( write operations write data to the end of the file.

  • O_NONBLOCK (set non-blocking mode).

Example

<?php
   $fd = dio_open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
   dio_close($fd);
?>
php_function_reference.htm
Advertisements