• PHP Video Tutorials

PHP - Direct I/O seek() Function



dio_seek() function can look for pos in fd from whence.

Syntax

int dio_seek( resource fd, int pos [, int whence] )

dio_seek() function can be used to change the position in a file with a resource descriptor.

The whence parameter can specify how the pos position could be interpreted −

  • SEEK_SET − pos is specified from the beginning of the file.

  • SEEK_CUR − Specify that pos is the number of characters from the current position in the file, and this amount can be positive or negative.

  • SEEK_END − Specifies that pos is the number of characters from the end of a file. A negative value can specify the position within the current file size, and a positive value can specify the position after the end of the file. If we set a position after the current end of the file and write data, we can expand the file with zeros to this position.

Example

<?php
   $fd = dio_open("/dev/ttyS0", O_RDWR);  
   dio_seek($fd, 10, SEEK_SET); 
   dio_seek($fd, -2, SEEK_CUR);
   dio_seek($fd, -5, SEEK_END);
   dio_seek($fd, 10, SEEK_END);
   dio_close($fd);
?>
php_function_reference.htm
Advertisements