Home > php教程 > php手册 > PHP 中的几种进程间共享内存使用方式

PHP 中的几种进程间共享内存使用方式

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:11:45
Original
1692 people have browsed it

1. 最常见的 APC 可以缓存 PHP 的 opcode 提高应用的性能 可以在同个 PHP-FPM 进程池的进程间共享数据 常用功能: apc_store apc_fetch apc_add apc_delete apc_inc apc_dec apc_cas apc_clear_cache apc_sma_info 2. Shmop Unix 系统共享内存使用接口 常用功

1. 最常见的 APC

可以缓存 PHP 的 opcode 提高应用的性能

可以在同个 PHP-FPM 进程池的进程间共享数据

常用功能:

apc_store apc_fetch

apc_add apc_delete

apc_inc apc_dec

apc_cas

apc_clear_cache

apc_sma_info

2. Shmop Unix 系统共享内存使用接口

常用功能:

shmop_open shmop_close

shmop_read shmop_write

shmop_delete

ipcs -m ?查看本机共享内存的状态和统计

ipcrm -m shmid 或 ipcrm -M shmkey 清除共享内存中的数据

3. SystemV Shm

常用功能:

ftok

shm_attach shm_detach

shm_put_var shm_get_var shm_remove_var

4. 使用共享内存需要考虑操作的原子性和锁、并行和互斥

sem 信号量相关函数:

sem_get sem_remove

sem_acquire sem_release (保证原子性)

其他常见锁机制:文件锁机制 flock

5. PHP 提供的 IPC 机制

–enable-shmop 共享内存,只能按字节操作

–enable-sysvsem 信号量

–enable-sysvshm 共享内存,和 shmop 的差别是提供的操作函数不同,支持 key、value操作

–enable-sysvmsg 消息队列

参考:

http://php.net/manual/zh/book.apc.php

http://docstore.mik.ua/orelly/webprog/pcook/ch05_07.htm

http://www.re-cycledair.com/php-dark-arts-shared-memory-segments-ipc

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template