C. 공유 메모리 함수
Shmop는 Unix 공유 메모리 세그먼트를 php에서 읽고, 기록하고, 생성하고, 삭제하기 쉽도록 하는 함수 모음이다. 이 함수는 윈도우즈에서는 공유 메모리를 지원하지 않기 때문에 동작하지 않는다. shmop를 사용하기 위해서는 --enable-shmop 인자로 php를 컴파일해야한다.
참고: 이번 장에서는 PHP 4.0.3의 shm_() 단어로 시작되는 함수를 설명할 것이다. 그러나 PHP 4.0.4 이후 버전의 경우 shmop_()로 이름만 바뀌었다.
- 차례
- shmop_close--공유 메모리 블럭을 닫음
- shmop_delete--공유 메모리 블럭을 삭제
- shmop_open--공유 메모리 블럭을 열거나 생성
- shmop_read--공유 메모리 블럭으로부터 데이터를 판독
- shmop_size--Get size of shared memory block
- shmop_write--공유 메모리 블럭에 자료 기록
- shmop_close--공유 메모리 블럭을 닫음
add a note User Contributed Notes
공유 메모리 함수
공유 메모리 함수
hackie at prohost dot org
27-Sep-2005 01:33
27-Sep-2005 01:33
It's not the job of the shmop extension to provide locking, there are many locking schemes avalible, if you need some sort of atomic operations choose a locking scheme that suits you and use it.
adamstevenson at _NOSPAM_ gmail dot com
13-Apr-2005 04:12
13-Apr-2005 04:12
Here is a little caching script that uses shared memory. It provides some examples on how to use some of the functions. http://www.adamstevenson.net/mycached.phps
Helped me to cut down some of my page requests from 2 seconds to .035 seconds.
Craig Manley
07-Jan-2005 08:19
07-Jan-2005 08:19
Since there is no mention of the (lack of) need for locking here, I took a look into the shmop.c extensions code. So correct me if I'm wrong, but the shmop.c extension uses memcpy() to copy strings to and from shared memory without any form of locking, and as far as I know, memcpy() is not atomic.
If that's true as I suspect, then these 'easy to use' functions are not so 'easy to use' any more and have to be wrapped in locks (e.g. semaphores, flocks, whatever).
joeldg AT listbid.com
03-May-2003 04:48
03-May-2003 04:48
Just so you know, the ftok function is probably the best for getting the key.. just so there are not people confused with how they are coming up with these hex codes for the id.
$fsize = filesize("/home/joeldg/testdata");
$fdata = file_get_contents("/home/joeldg/testdata");
$shm_id = shmop_open(ftok("/home/joeldg/testdata", 'R'), "c", 0644, $fsize);
stoimenov at email dot com
24-Jul-2002 09:18
24-Jul-2002 09:18
Windows does support shared memory through memory mapped file. Check the following functions for details:
* CreateFileMapping
* MapViewOfFile
hackie at misato dot prohost dot org
02-May-2002 10:15
02-May-2002 10:15
Your segment probobly doesn't exist. You should probobly be using the c flag...
"a" for access (sets SHM_RDONLY for shmat) use this flag when you need to open an existing shared memory segment for read only
"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
rei at prohost dot org
12-Jan-2001 08:16
12-Jan-2001 08:16
The idea behind SHMOP is an easy to use shared memory interface,
without any additional headers added to the shared memory segment
or requiring any special special controls to access the shared memory
segment outside of PHP. SHMOP borrows its api from C's api to shm,
which makes it very easy to use, because it treats shared memory, like C, as
a file of sorts. This makes it very easy to use even for novices, due to this
functionality. Most importantly SHMOP uses shm segments to store raw data,
which means you don't need to worry about matching headers, etc... when you are
using C, perl or other programming languages to open/create/read/write shm segments
that were create or are going to be used by PHP. In this it differs from
sysvshm, who's shm interface uses a specialized header, which resides inside
the shared memory segment this adds an unnecessary level of difficulty when
you want to access php shm from external programs.
Also, from my personal tests in Linux 2.2/2.4 and FreeBSD 3.3 SHMOP is about
20% faster then sysvshm, mostly due to fact it does not need to parse the
specialized header and stores the data in raw form.
slavapl at mailandnews dot com
12-Jan-2001 08:02
12-Jan-2001 08:02
What you need to realise is that sysvshm is extremly php oriented in it's ability, it's quite a kludge interfacing other NON PHP utilities with it. For example have you tried using sysvshm to read an shm segment NOT created by php? It's not possible, because sysvshm uses a proprietry format, in essense it can ONLY be used within PHP unless of course you take time to figure out this format.
So basically, the purpose of shmop is to provide a symple interface to shared memory that can be used with OTHER NON php shm creators.
Hope this clears it up.
'PHP관련' 카테고리의 다른 글
php 에서 사용하기 위한 라이브러리 설치 모음 (0) | 2011.10.14 |
---|---|
4,000 바이트 제한이 문제가 되십니까? LOB를 활용하십시오... (0) | 2011.10.14 |
시스템 모니터링 툴」제작기 (0) | 2011.10.14 |
그래프(chart ... )를 그려 보자 ㅡㅡ; (0) | 2011.10.14 |
초급용 php : 게시판의 꽃 페이징을 아십니까? (0) | 2011.10.14 |