php 共用記憶體

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   strong   資料   

 

共用記憶體主要用於處理序間通訊

 php中的共用記憶體有兩套擴充可以實現

1、shmop  編譯時間需要開啟 --enable-shmop 參數

執行個體:

  

$shm_key = ftok(__FILE__, ‘t‘);/** 開闢一塊共用記憶體 int $key , string $flags , int $mode , int $size $flags: a:訪問唯讀記憶體段        c:建立一個新記憶體段,或者如果該記憶體段已存在,嘗試開啟它進行讀寫        w:可讀寫的記憶體段        n:建立一個新記憶體段,如果該記憶體段已存在,則會失敗$mode: 八進位格式  0655$size: 開闢的資料大小 位元組 */$shm_id = shmop_open($shm_key, "c", 0644, 1024);/** * 寫入資料 資料必須是字串格式 , 最後一個指位移量 * 注意:位移量必須在指定的範圍之內,否則寫入不了 *  */$size = shmop_write($shm_id, ‘songjiankang‘, 0);echo "write into {$size}";#讀取的範圍也必須在申請的記憶體範圍之內,否則失敗$data = shmop_read($shm_id, 0, 100);var_dump($data);#刪除 只是做一個刪除標誌位,同時不在允許新的進程進程讀取,當在沒有任何進程讀取時系統會自動刪除shmop_delete($shm_id);#關閉該記憶體段shmop_close($shm_id);

 

 

 

參考:http://www.laruence.com/2008/04/21/101.html

    http://www.yuansir-web.com/2012/09/22/php

 

php 共用記憶體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.