<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >dio_fcntl</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Direct IO Functions" HREF="ref.dio.html"><LINK REL="PREVIOUS" TITLE="dio_close" HREF="function.dio-close.html"><LINK REL="NEXT" TITLE="dio_open" HREF="function.dio-open.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.dio-close.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.dio-open.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.dio-fcntl" ></A >dio_fcntl</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN32919" ></A ><P > (PHP 4 >= 4.2.0, PHP 5 <= 5.0.4)</P >dio_fcntl -- Performs a c library fcntl on fd</DIV ><DIV CLASS="refsect1" ><A NAME="AEN32922" ></A ><H2 >Descrição</H2 >mixed <B CLASS="methodname" >dio_fcntl</B > ( resource fd, int cmd [, mixed args] )<BR ></BR ><P > The <B CLASS="function" >dio_fcntl()</B > function performs the operation specified by <CODE CLASS="parameter" >cmd</CODE > on the file descriptor <CODE CLASS="parameter" >fd</CODE >. Some commands require additional arguments <CODE CLASS="parameter" >args</CODE > to be supplied. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B >esta função não é implementada na plataforma Windows</P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN32943" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >fd</CODE ></DT ><DD ><P > The file descriptor returned by <A HREF="function.dio-open.html" ><B CLASS="function" >dio_open()</B ></A >. </P ></DD ><DT ><CODE CLASS="parameter" >cmd</CODE ></DT ><DD ><P > Can be one of the following operations: <P ></P ><UL ><LI ><P > <TT CLASS="constant" ><B >F_SETLK</B ></TT > - Lock is set or cleared. If the lock is held by someone else <B CLASS="function" >dio_fcntl()</B > returns -1. </P ></LI ><LI ><P > <TT CLASS="constant" ><B >F_SETLKW</B ></TT > - like <TT CLASS="constant" ><B >F_SETLK</B ></TT >, but in case the lock is held by someone else, <B CLASS="function" >dio_fcntl()</B > waits until the lock is released. </P ></LI ><LI ><P > <TT CLASS="constant" ><B >F_GETLK</B ></TT > - <B CLASS="function" >dio_fcntl()</B > returns an associative array (as described above) if someone else prevents lock. If there is no obstruction key "type" will set to <TT CLASS="constant" ><B >F_UNLCK</B ></TT >. </P ></LI ><LI ><P > <TT CLASS="constant" ><B >F_DUPFD</B ></TT > - finds the lowest numbered available file descriptor greater than or equal to <CODE CLASS="parameter" >args</CODE > and returns them. </P ></LI ><LI ><P > <TT CLASS="constant" ><B >F_SETFL</B ></TT > - Sets the file descriptors flags to the value specified by <CODE CLASS="parameter" >args</CODE >, which can be <TT CLASS="constant" ><B >O_APPEND</B ></TT >, <TT CLASS="constant" ><B >O_NONBLOCK</B ></TT > or <TT CLASS="constant" ><B >O_ASYNC</B ></TT >. To use <TT CLASS="constant" ><B >O_ASYNC</B ></TT > you will need to use the <A HREF="ref.pcntl.html" >PCNTL</A > extension. </P ></LI ></UL > </P ></DD ><DT ><CODE CLASS="parameter" >args</CODE ></DT ><DD ><P > <CODE CLASS="parameter" >args</CODE > is an associative array, when <CODE CLASS="parameter" >cmd</CODE > is <TT CLASS="constant" ><B >F_SETLK</B ></TT > or <TT CLASS="constant" ><B >F_SETLLW</B ></TT >, with the following keys: <P ></P ><UL ><LI ><P > "start" - offset where lock begins </P ></LI ><LI ><P > "length" - size of locked area. zero means to end of file </P ></LI ><LI ><P > "wenth" - Where l_start is relative to: can be <TT CLASS="constant" ><B >SEEK_SET</B ></TT >, <TT CLASS="constant" ><B >SEEK_END</B ></TT > and <TT CLASS="constant" ><B >SEEK_CUR</B ></TT > </P ></LI ><LI ><P > "type" - type of lock: can be <TT CLASS="constant" ><B >F_RDLCK</B ></TT > (read lock), <TT CLASS="constant" ><B >F_WRLCK</B ></TT > (write lock) or <TT CLASS="constant" ><B >F_UNLCK</B ></TT > (unlock) </P ></LI ></UL > </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN33010" ></A ><H2 >Valores de retornado</H2 ><P > Returns the result of the C call. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN33013" ></A ><H2 >Exemplos</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN33016" ></A ><P ><B >Exemplo 1. Setting and clearing a lock</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$fd </font><font color="#007700">= </font><font color="#0000BB">dio_open</font><font color="#007700">(</font><font color="#DD0000">'/dev/ttyS0'</font><font color="#007700">, </font><font color="#0000BB">O_RDWR</font><font color="#007700">);<br /><br />if (</font><font color="#0000BB">dio_fcntl</font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">, </font><font color="#0000BB">F_SETLK</font><font color="#007700">, Array(</font><font color="#DD0000">"type"</font><font color="#007700">=></font><font color="#0000BB">F_WRLCK</font><font color="#007700">)) == -</font><font color="#0000BB">1</font><font color="#007700">) {<br /> </font><font color="#FF8000">// the file descriptor appears locked<br /> </font><font color="#007700">echo </font><font color="#DD0000">"The lock can not be cleared. It is held by someone else."</font><font color="#007700">;<br />} else {<br /> echo </font><font color="#DD0000">"Lock succesfully set/cleared"</font><font color="#007700">;<br />}<br /><br /></font><font color="#0000BB">dio_close</font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.dio-close.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.dio-open.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >dio_close</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.dio.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >dio_open</TD ></TR ></TABLE ></DIV ></BODY ></HTML >