note 81230 added to ref.sem
| From: | alexh at southwestmicrowave dot com | Date: | Tue, 19 Feb 2008 17:24:37 +0000 |
| Subject: | note 81230 added to ref.sem | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136278@lists.php.net to get a copy of this message | ||
I've had a devil of a time interfacing with non-PHP declared shared memory. DO NOT do this
unless you read the php-X.X.X/ext/sysvshm/ code directly. Non-PHP programs need to use exactly the
same "shared memory" struct as PHP uses, otherwise this "system V standard" call
doesn't work.
Here are the specific deviations from the System-V C-calls:
<?
$shmkey = ftok($shmkey_path, $shmkey_proj_id);
?>
In C the $shmkey_proj_id is an int, but in PHP it's a char* to a single char. This means that
your C program is restricted to using 0-255 (in PHP chr(0) through chr(255)) for project ID's,
if it used anything else then you have to re-write your C-routine.
<?
$var = shm_get_var($shm_id, 0);
$fail = shm_put_var($shm_id, 0, $var1 )
?>
There are no such things as a system V calls like this at all. In system V you simply have a
pointer to the beginning of your shared memory segment after attaching, so as long as you offset to
the right spot you get what you want. In PHP, shared memory is ONLY cast as a struct, and the
"data" is serialized as a string in the "mem" portion of the struct:
<? //C code
typedef struct {
long key;
long length;
long next;
char mem;
} sysvshm_chunk;
?>
If your C program didn't use this struct you need to re-write it to use this struct and write
everything as a string.
This is rather absurd, as the purpose of shared memory is to communicate quickly with other programs
resident in memory. But it is what it is.
----
Server IP: 64.71.164.2
Probable Submitter: 206.169.62.98
----
Manual Page -- http://www.php.net/manual/en/ref.sem.php
Edit -- https://master.php.net/note/edit/81230
Del: integrated -- https://master.php.net/note/delete/81230/integrated
Del: useless -- https://master.php.net/note/delete/81230/useless
Del: bad code -- https://master.php.net/note/delete/81230/bad+code
Del: spam -- https://master.php.net/note/delete/81230/spam
Del: non-english -- https://master.php.net/note/delete/81230/non-english
Del: in docs -- https://master.php.net/note/delete/81230/in+docs
Del: other reasons-- https://master.php.net/note/delete/81230
Reject -- https://master.php.net/note/reject/81230
Search -- https://master.php.net/manage/user-notes.php