// Create 100 byte shared memory block with system id of 0xff3 $shm_id = shmop_open(0xff3, "c", 0644, 100); if (!$shm_id) { echo "Couldn't create shared memory segment\n"; }// Get shared memory block's size $shm_size = shmop_size($shm_id); echo "SHM Block Size: " . $shm_size . " has been created.\n";// Lets write a test string into shared memory $shm_bytes_written = shmop_write($shm_id, "my shared memory block", 0); if ($shm_bytes_written != strlen("my shared memory block")) { echo "Couldn't write the entire length of data\n"; }// Now lets read the string back $my_string = shmop_read($shm_id, 0, $shm_size); if (!$my_string) { echo "Couldn't read from shared memory block\n"; } echo "The data inside shared memory was: " . $my_string . "\n";//Now lets delete the block and close the shared memory segment if (!shmop_delete($shm_id)) { echo "Couldn't shared memory block for deletion."; } shmop_close($shm_id);
这方面的东西还真没接触过
这个还是比较赞同的,
不过该用的时候也应该用阿:P
呵呵,就像php提供字符大小写转换函数,有些人直接用,有些人非要自己写。显然,直接用会好点阿:P呵呵,仅仅是想了解下php这方面的应用,希望吸收点应验而已:Pto iasky(iasky):
memcached,分布式内存缓存?这个不太了解哦。能给说说经验不?大家还有什么其他应用方面的应验不?
现在的web应用对于性能的要求越来越高了:P
Shared Memory Functions
===========================
<?php
// Create 100 byte shared memory block with system id of 0xff3
$shm_id = shmop_open(0xff3, "c", 0644, 100);
if (!$shm_id) {
echo "Couldn't create shared memory segment\n";
}// Get shared memory block's size
$shm_size = shmop_size($shm_id);
echo "SHM Block Size: " . $shm_size . " has been created.\n";// Lets write a test string into shared memory
$shm_bytes_written = shmop_write($shm_id, "my shared memory block", 0);
if ($shm_bytes_written != strlen("my shared memory block")) {
echo "Couldn't write the entire length of data\n";
}// Now lets read the string back
$my_string = shmop_read($shm_id, 0, $shm_size);
if (!$my_string) {
echo "Couldn't read from shared memory block\n";
}
echo "The data inside shared memory was: " . $my_string . "\n";//Now lets delete the block and close the shared memory segment
if (!shmop_delete($shm_id)) {
echo "Couldn't shared memory block for deletion.";
}
shmop_close($shm_id);
?>
楼上的,手册上的就不要了吧
这个只是举例说明在php中提供了什么样的共享内存,如果简单的使用共享内存本身而已。并没有任何实际用处,仅仅帮你了解下而已。连如何请求释放信号量里面都没。
不过这些都是基础语法拉,就不用了。谢谢了路过的高手们,用过的请给点指点啊,谢谢哈!
你到c/unix/linux版去问,那边这个几乎是肯定要用到的。
我是想知道目前得web应用中哪些地方会用到它,并且怎么用。:P
听说聊天室可以用,个人想来确实会好得多,但不知道怎么用。。
得不偿失。 目前还没有看到哪个php产品用的。
re:在windows系统中一样可以使用