<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >shmop_open</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Shared Memory Functions" HREF="ref.shmop.html"><LINK REL="PREVIOUS" TITLE="shmop_delete" HREF="function.shmop-delete.html"><LINK REL="NEXT" TITLE="shmop_read" HREF="function.shmop-read.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></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 PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.shmop-delete.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.shmop-read.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.shmop-open" ></A >shmop_open</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN103668" ></A ><P > (PHP 4 >= 4.0.4, PHP 5)</P >shmop_open -- Create or open shared memory block</DIV ><DIV CLASS="refsect1" ><A NAME="AEN103671" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >shmop_open</B > ( int key, string flags, int mode, int size)<BR ></BR ><P > <B CLASS="function" >shmop_open()</B > can create or open a shared memory block. </P ><P > <B CLASS="function" >shmop_open()</B > takes 4 parameters: key, which is the system's id for the shared memory block, this parameter can be passed as a decimal or hex. The second parameter are the flags that you can use: <P ></P ><UL ><LI ><P > "a" for access (sets SHM_RDONLY for shmat) use this flag when you need to open an existing shared memory segment for read only </P ></LI ><LI ><P > "c" for create (sets IPC_CREATE) use this flag when you need to create a new shared memory segment or if a segment with the same key exists, try to open it for read and write </P ></LI ><LI ><P > "w" for read & write access use this flag when you need to read and write to a shared memory segment, use this flag in most cases. </P ></LI ><LI ><P > "n" create a new memory segment (sets IPC_CREATE|IPC_EXCL) use this flag when you want to create a new shared memory segment but if one already exists with the same flag, fail. This is useful for security purposes, using this you can prevent race condition exploits. </P ></LI ></UL > The third parameter is the mode, which are the permissions that you wish to assign to your memory segment, those are the same as permission for a file. Permissions need to be passed in octal form ex. 0644. The last parameter is size of the shared memory block you wish to create in bytes. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Notã: </B > Note: the 3rd and 4th should be entered as 0 if you are opening an existing memory segment. On success <B CLASS="function" >shmop_open()</B > will return an id that you can use to access the shared memory segment you've created. </P ></BLOCKQUOTE ></DIV > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN103705" ></A ><P ><B >Exemplu 1. Create a new shared memory block</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$shm_key </font><font color="#007700">= </font><font color="#0000BB">ftok</font><font color="#007700">(</font><font color="#0000BB">__FILE__</font><font color="#007700">, </font><font color="#DD0000">'t'</font><font color="#007700">);<br /></font><font color="#0000BB">$shm_id </font><font color="#007700">= </font><font color="#0000BB">shmop_open</font><font color="#007700">(</font><font color="#0000BB">$shm_key</font><font color="#007700">, </font><font color="#DD0000">"c"</font><font color="#007700">, </font><font color="#0000BB">0644</font><font color="#007700">, </font><font color="#0000BB">100</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > This example opened a shared memory block with a system id returned by <A HREF="function.ftok.html" ><B CLASS="function" >ftok()</B ></A >. </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.shmop-delete.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.shmop-read.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >shmop_delete</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.shmop.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >shmop_read</TD ></TR ></TABLE ></DIV ></BODY ></HTML >