1. 程式人生 > >給PHP開啟shmop擴展實現共享內存

給PHP開啟shmop擴展實現共享內存

efi color 客戶 圖片 col 執行命令 AD 內存 figure

在項目開發中,想要實現PHP多個進程之間共享數據的功能,讓客戶端連接能夠共享一個狀態,需要開啟共享內存函數shmop。如果預期考慮會遇到這方面需求,那麽最好在編譯PHP的時候添加--with-shmop選項。但是編譯的時候沒有添加,只能在重新編譯配置了。

一、找到php源碼包裏的擴展目錄,進入shmop

# cd /usr/local/src/php-7.1.10/ext/shmop/

二、執行phpize,生成配置

# phpize
[root@bogon shmop]# ls
acinclude.m4    build         config.h.in  config.nice    configure     CREDITS     libtool    Makefile.fragments  missing        package2.xml  README         shmop.la
aclocal.m4      config.guess  config.log   config.status  configure.
in include ltmain.sh Makefile.global mkinstalldirs package.xml run-tests.php shmop.lo autom4te.cache config.h config.m4 config.sub config.w32 install-sh Makefile Makefile.objects modules php_shmop.h shmop.c tests

三、執行命令開始編譯

# ./configure --with-php-config=/usr/local/php/bin/php-config
# make 
&& make install
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Dont forget to run make test.

Installing shared extensions:     
/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/

四、修改php.ini開啟擴展

復制返回的那行路徑:/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/

# vim /usr/local/php/etc/php.ini
;extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/shmop.so   //添加此行代碼,後面跟上shmop.so

重啟php

技術分享圖片

給PHP開啟shmop擴展實現共享內存