Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 670

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>flock</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Filesystem functions"
HREF="ref.filesystem.html"><LINK
REL="PREVIOUS"
TITLE="filetype"
HREF="function.filetype.html"><LINK
REL="NEXT"
TITLE="fnmatch"
HREF="function.fnmatch.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></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"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.filetype.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.fnmatch.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.flock"
></A
>flock</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN25789"
></A
><P
>    (PHP 3&#62;= 3.0.7, PHP 4 )</P
>flock&nbsp;--&nbsp;Portable advisory file locking</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN25792"
></A
><H2
>Description</H2
>bool <B
CLASS="methodname"
>flock</B
> ( resource handle, int operation [, int &#38;wouldblock])<BR
></BR
><P
>&#13;     PHP supports a portable way of locking complete files in an
     advisory way (which means all accessing programs have to use the
     same way of locking or it will not work).
    </P
><P
>&#13;     <B
CLASS="function"
>flock()</B
> operates on <TT
CLASS="parameter"
><I
>handle</I
></TT
>
     which must be an open file
     pointer. <TT
CLASS="parameter"
><I
>operation</I
></TT
> is one of the following
     values:
    </P
><P
>&#13;     <P
></P
><UL
><LI
><P
>&#13;         To acquire a shared lock (reader), set
         <TT
CLASS="parameter"
><I
>operation</I
></TT
> to<TT
CLASS="constant"
><B
>LOCK_SH</B
></TT
> (set to 1 prior to
         PHP 4.0.1).
       </P
></LI
><LI
><P
>&#13;         To acquire an exclusive lock (writer), set
         <TT
CLASS="parameter"
><I
>operation</I
></TT
> to <TT
CLASS="constant"
><B
>LOCK_EX</B
></TT
> (set to 2 prior to
         PHP 4.0.1).
       </P
></LI
><LI
><P
>&#13;         To release a lock (shared or exclusive), set
         <TT
CLASS="parameter"
><I
>operation</I
></TT
> to <TT
CLASS="constant"
><B
>LOCK_UN</B
></TT
> (set to 3 prior to
         PHP 4.0.1).
       </P
></LI
><LI
><P
>&#13;         If you don't want <B
CLASS="function"
>flock()</B
> to block while
         locking, add <TT
CLASS="constant"
><B
>LOCK_NB</B
></TT
> (4 prior to PHP 4.0.1) to
         <TT
CLASS="parameter"
><I
>operation</I
></TT
>.
       </P
></LI
></UL
>
    </P
><P
>&#13;     <B
CLASS="function"
>flock()</B
> allows you to perform a simple
     reader/writer model which can be used on virtually every platform
     (including most Unix derivatives and even Windows).  The optional third
     argument is set to <TT
CLASS="constant"
><B
>TRUE</B
></TT
> if the lock would block (EWOULDBLOCK
     errno condition)
    </P
><P
>&#13;      Returns <TT
CLASS="constant"
><B
>TRUE</B
></TT
> on success or <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on failure.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
      Because <B
CLASS="function"
>flock()</B
> requires a file pointer, you may have
      to use a special lock file to protect access to a file that you intend
      to truncate by opening it in write mode (with a "w" or "w+" argument to
      <A
HREF="function.fopen.html"
><B
CLASS="function"
>fopen()</B
></A
>).
     </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Warning</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;      <B
CLASS="function"
>flock()</B
> will not work on NFS and many other networked
      file systems. Check your operating system documentation for more
      details.
     </P
><P
>&#13;      On some operating systems <B
CLASS="function"
>flock()</B
> is implemented at
      the process level. When using a multithreaded server API like ISAPI you
      may not be able to rely on <B
CLASS="function"
>flock()</B
> to protect files
      against other PHP scripts running in parallel threads of the same server
      instance!
     </P
><P
>&#13;      <B
CLASS="function"
>flock()</B
> is not supported on antiquated filesystems like
      <TT
CLASS="literal"
>FAT</TT
> and its derivates and will therefore always
      return <TT
CLASS="constant"
><B
>FALSE</B
></TT
> under this environments (this is especially true for
      Windows 98 users).
     </P
></TD
></TR
></TABLE
></DIV
></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.filetype.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.fnmatch.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>filetype</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.filesystem.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>fnmatch</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>