php共享記憶體相關函式

2021-06-09 21:49:04 字數 1254 閱讀 6510

共享記憶體函式類似於檔案操作函式,但無需處理乙個流,您將處理乙個共享記憶體訪問 id。

/***@param int $key 標識系統中的共享記憶體段的數字

@parma string $flags 訪問模式,它非常類似於fopen函式的訪問模式

@param int $mode 記憶體段的許可權。您必須在這裡提供乙個八進位制值。如 0777

@param int $size 記憶體段大小,以位元組為單位。在寫入乙個記憶體段之前,您必須在它之上分配適當的位元組數。

@return mix 返回乙個 id 編號,其他函式可使用該 id 編號操作該共享記憶體段。這個 id 是共享記憶體訪問 id,與系統 id 不同。如果失敗,shmop_open將返回 false。 */

shmop_open(int

$key

, string

$flags

, int

$mode

, int

$size)

/**

@param int $shmid shmop_open()返回的id 識別您操作的共享記憶體塊

@param string $data  希望儲存的資料

@param int  $offset 希望開始寫入的位置。預設情況下,我們始終使用 0 來表示開始寫入的位置

@return 失敗時會返回 false,在成功時會返回寫入的位元組數。*/

shmop_write( int

$shmid

, string

$data

, int

$offset )

/**@param int $shmid shmop_open()返回的id

@param int $start 從記憶體段讀取的位置

@param int $count 讀取多少位元組 */

shmop_read( int

$shmid

, int

$start

, int

$count )

//接下來的幾個就比較容易了

$size = shmop_size($shmid);//記憶體段大小,以位元組為單位
shmop_delete($shmid); //刪除記憶體段
shmop_close($shmid);//完成crud操作後要關閉

具體的例子可以看

php 共享記憶體學習 shmop函式

問題 希望可以在程序間共享變數,為共享資料提供快速訪問 解決方案 除了可以使用apc模組,還可以用shmop或system v共享記憶體 1 建立鍵 2 將乙個可訪問的檔案路徑名轉換為乙個可供 shmop open 和其他系統vipc keys使用的整數,proj引數必須是乙個字串,這個引數其實就是...

php 共享記憶體

共享記憶體主要用於程序間通訊 php中的共享記憶體有兩套擴充套件可以實現 1 shmop 編譯時需要開啟 enable shmop 引數 例項 shm key ftok file t 開闢一塊共享記憶體 int key string flags int mode int size flags a 訪...

shmop 系列函式使用 php共享記憶體

1 shmop 系列函式使用 使用shmop 系列函式 set time limit 0 shm key ftok file t shm id shmop open shm key,c 0655,1024 size shmop write shm id,hello world php eol,0 s...