note 72563 added to function.shm-attach
| From: | UtherPendragon at osu1 dot php dot net | Date: | Wed, 24 Jan 2007 16:26:09 +0000 |
| Subject: | note 72563 added to function.shm-attach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122142@lists.php.net to get a copy of this message | ||
Since there aren't seperate functions for CREATING and ATTACHING shared memory (a mistake in my
opinion), you might want to do some testing to check whether you've created it or not, as you
may not want the slave of a master/slave pair to ever create the shared memory.
One way you can test this is by having your slave set the size to something small, then testing the
size by putting a variable too large to fit, e.g.:
function get_shmem() {
return shm_attach(ftok('somefile.txt', 'T'), 100, 0644);
}
$shm = get_shmem();
while (!@shm_put_var($shm, 1, str_repeat('.....', 20))) {
shm_remove($shm);
sleep(1);
//we created it, so we'll remove it and sleep to wait for the master to create it, then
try again.
$shm = get_shmem();
}
shm_remove_var($shm, 1);
//here we know the shared memory was already created, because we could put a variable in bigger than
the size requested.
Another way you can handle it is to have all programs initialize the shared memory with the same
parameters... I had a problem with this when my clients starting too fast and created the shmem
without passing a memsize value, so it was defaulting to 10k which was too small.
----
Server IP: 216.194.113.175
Probable Submitter: 69.26.240.90
----
Manual Page -- http://www.php.net/manual/en/function.shm-attach.php
Edit -- https://master.php.net/note/edit/72563
Del: integrated -- https://master.php.net/note/delete/72563/integrated
Del: useless -- https://master.php.net/note/delete/72563/useless
Del: bad code -- https://master.php.net/note/delete/72563/bad+code
Del: spam -- https://master.php.net/note/delete/72563/spam
Del: non-english -- https://master.php.net/note/delete/72563/non-english
Del: in docs -- https://master.php.net/note/delete/72563/in+docs
Del: other reasons-- https://master.php.net/note/delete/72563
Reject -- https://master.php.net/note/reject/72563
Search -- https://master.php.net/manage/user-notes.php