PHP.nl

dio_fcntl

dio_fcntl

Performs a c library fcntl on fd

mixed **dio_fcntl** resource $fd int $cmd mixed $args

The function performs the operation specified by on the file descriptor . Some commands require additional arguments to be supplied. dio_fcntl``cmd``fd``args

fd The file descriptor returned by . dio_open

cmd Can be one of the following operations:

  - - Lock is set or cleared. If the lock           is held by someone else  returns           -1.          `F_SETLK``dio_fcntl`
    • like , but in case the lock is held by someone else, waits until the lock is released. F_SETLKW``F_SETLK``dio_fcntl
    •         returns an associative array (as described below) if someone else           prevents lock. If there is no obstruction key "type" will set           to .          `F_GETLK``dio_fcntl``F_UNLCK`
      
    • finds the lowest numbered available file descriptor greater than or equal to and returns them. F_DUPFD``args
    • Sets the file descriptors flags to the value specified by , which can be , or . To use you will need to use the extension. F_SETFL``args``O_APPEND``O_NONBLOCK``O_ASYNC``O_ASYNCPCNTL

args is an associative array, when is or , with the following keys:

  `args``cmd``F_SETLK``F_SETLLW`- - offset where lock begins          `start`
    • size of locked area. zero means to end of file length
    • Where l_start is relative to: can be , and whence``SEEK_SET``SEEK_END``SEEK_CUR
    • type of lock: can be (read lock), (write lock) or (unlock) type``F_RDLCK``F_WRLCK``F_UNLCK

Returns the result of the C call.

Voorbeeld: Setting and clearing a lock

<?php

$fd = dio_open('/dev/ttyS0', O_RDWR);

if (dio_fcntl($fd, F_SETLK, Array("type"=>F_WRLCK)) == -1) {
   // the file descriptor appears locked
   echo "The lock can not be cleared. It is held by someone else.";
} else {
   echo "Lock successfully set/cleared";
}

dio_close($fd);
?>