(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
shmop_read — Lee datos a partir de un bloque
shmop_read() lee una cadena en un bloque de memoria compartida.
shmopoffsetsizeoffset y size
debe ser inferior o igual a la longitud real del segmento de memoria compartida.
0 lee shmop_size($shmid) - $start bytes.
Devuelve los datos.
Si offset o size están fuera del rango,
se lanza una ValueError .
| Versión | Descripción |
|---|---|
| 8.0.0 |
shmop ahora requiere una instancia de Shmop
en lugar de un resource .
|
| 8.0.0 |
Si offset o size están fuera de límite,
se lanza una ValueError ; anteriormente se emitía una E_WARNING
y se devolvía false .
|
Ejemplo #1 Lee un bloque de memoria compartida
<?php
$shm_data = shmop_read($shm_id, 0, 50);
?>
Este ejemplo lee 50 bytes del bloque de memoria compartida
y los coloca en $shm_data.
shmop_read() reads and returns the whole memory segment's data. This is not useful if you're just working with strings. If you need to read a string from shared memory, call str_from_mem() on the result of shmop_read(). Similarly when writing strings to memory (instead of binary data), null terminate your strings with str_to_nts() before passing the value on to shmop_write().
function str_to_nts($value) {
return "$value0円";
}
function str_from_mem(&$value) {
$i = strpos($value, "0円");
if ($i === false) {
return $value;
}
$result = substr($value, 0, $i);
return $result;
}When i need to read the whole string at that shm pointer, setting the count parameter to zero (0) seems work for me.With shmop_read, you probably get a "0円" - padded string.
$zero_padded = shmop_read($shm_seg, 0, 128);
$usable_string = rtrim($zero_padded, "0円");Also you can use the shmop_size() function to determine the block size.