Hello.

I don't understand it at all.  I'm trying to cache some data in a shared
memory segment with PHP 4.0.4pl1's shm functions.

I do this like this:

<?php
$key["shm"] = 0x4711;
$key["var"] = 0x0815;

$file = "services";
$size = filesize( $file );
$fd = fopen( $file, "r" );
$data = fread( $fd, $size );
fclose( $fd );

$magic_size_shm = 42; /********* ?????????????? WHY ????????? *********/

$size_data = strlen( $data );
$size_shm  = strlen( serialize( $data ) ) + $magic_size_shm;

$shm = shm_attach( $key["shm"], $size_shm );

$data_shm = @shm_get_var( $shm, $key["var"] );

if( ! $data_shm ){
  shm_put_var( $shm, $key["var"], $data );
  $data_shm = shm_get_var( $shm, $key["var"] );
}

shm_detach( $shm );
?>

What I don't understand at all is, why I need to add this "$magic_size_shm"
to the "strlen( serialize( $data ) )" value.  The value I need to add seems
to be always between 41 and 49, but it varies depending on the data I want
to store.

According to the manual and the comments there, I'd have thought that it is
enough to just alloc "strlen( serialize( $data ) )" - why is that not so?

Now, before someone suggest to try shmop instead - this is not working at
all.  I've tried the example from the shmop manual page on php.net, and this
totally breaks.  These lines don't work at all on my system:

$shm_size = shmop_size($shm_id);
echo "SHM Block Size: ".$shm_size. " has been created.\n";

For my system, it returns totally varying values which are all WAY below 0,
like -1072562176, or -722337792 or -914554880 ....  Because of that, PHP
cannot access the shmop segment.

This is on a current Mandrake Cooker (beta) system with glibc 2.2.2, kernel
2.4.2 (also tried 2.4.3). PHP was compiled with gcc 2.96.

Someone please help me!

Alexander Skwar
-- 
How to quote:   http://learn.to/quote (german) http://quote.6x.to (english)
Homepage:       http://www.digitalprojects.com   |   http://www.iso-top.de
   iso-top.de - Die günstige Art an Linux Distributionen zu kommen
                Uptime: 1 day 8 hours 43 minutes

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to