* Thus wrote Chidanand:
>
> I have a requirement where in i have to access shared
> memory allocated by some C process. Can i do this in
> PHP?
>
> I am trying out some thing like this.
> I want to access the existing shared memory.
>
> $shm_id = ftok("/tmp/", 'm');
> echo "$shm_id". "<br>";
> $shmid = shmop_open($shm_id, "c", 0644, 164);
> $shm_data = shmop_read($shm_id, 0, 50);
you really want $shmid not $shm_id passed to shmop_read, the
$shm_id is basically a filehandle where the $shmid is the resource
to that file.
>
> Why is the shm_id generated from ftok in C and ftok in
> php different?
For me:
#include <sys/types.h>
#include <sys/ipc.h>
int main() {
int shmkey = 0;
shmkey = ftok("/tmp/", 'l');
printf("shmkey %d\n", shmkey);
}
Produces the same key as:
<?php
$shm_key = ftok("/tmp/", 'l');
echo "shm_key " . $shm_key, "\n";
Curt
--
The above comments may offend you. flame at will.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php