|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-02-12 15:07 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 16:00:02 2025 UTC |
I have a simple script that I'm trying to write/read to shared memory w/ the shmop_* functions. The problem is that it ALWAYS gives me php warnings when reading the value from shared memory. Doing some digging in the code it seems that shmop_write always copies a string to shared memory, but it NEVER null terminates it. This ALWAYS causes shmop_read to report php warnings of Warning: String is not zero-terminated (5?̏**?*@) (source: zend_execute_API.c:274) in Unknown on line 0 I can't turn warnings off, just to avoid this issue. I need warnings on for debugging of the rest of my site. MY question is, shouldn't shmop_write() always memcopy the stringlen + the NULL character, so when u do a read, this doesn't happen? I know, then u always have to add 1 to the shmop_read(), but isn't that normal to assume u'd want the strlen + 1 for the null char? Here is my script <?php function xmp_var_dump( $var ) { echo "<xmp>\n"; var_dump( $var ); echo "</xmp>\n"; } $key = 0x0ff; $semid = sem_get ( $key, 1, 0666 ); if ( !sem_acquire( $semid ) ) { echo "Can't acquire semaphore<BR>"; exit; } $size = 100; $shmid = shmop_open( $key, 'c', 0, 0 ); //shmop_delete($shmid); //shmop_close($shmid); //exit; if ( $shmid == '' ) { // Get register size: // Create shared memory block $shmid = shmop_open( $key, 'c', 0666, $size ); xmp_var_Dump( $shmid ); if ( $shmid == '' ) { echo "mem.mem: Can't create shared memory"; } else { // Set Header Info: xmp_var_dump( "writing test"); shmop_write( $shmid, 5, 0 ); } } else { $var = shmop_read( $shmid, 0, 1); xmp_var_dump( $var ); } shmop_close($shmid); if( !sem_release( $semid ) ) { echo "find: Can't release semaphore"; exit(); } ?> Warning: shmopen: can't get the block in /home/waboring/devel/current/php/fo/shmem/example3.php on line 22 int(2) string(12) "writing test" Warning: shwrite: write (5), len = 1 in /home/waboring/devel/current/php/fo/shmem/example3.php on line 38