Created
August 16, 2011 19:20
-
-
Save johnlettman-old/1149910 to your computer and use it in GitHub Desktop.
Persistent shared memory using PHP -- perfect for loading a webapplication's configuration one time only and quickly deserializing it per request. Faster than disk configuration mediums, including PHP-file configs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Open the memory location; read-only. | |
$memoryHandle = shmop_open(0x13c, "a", 0644, 100); | |
// Read the memory location and print it. | |
$string = shmop_read($memoryHandle, 0, 0); # Setting the byte count to 0 reads all bytes. | |
echo 'Data in RAM reads: '.$string; | |
shmop_close($memoryHandle); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Open the memory location; create/write. | |
$memoryHandle = shmop_open(0x13c, "c", 0644, 100); | |
// Set the data from the GET variable. | |
if(isset($_GET['data'])) { | |
shmop_write($memoryHandle, $_GET['data'], 0); | |
echo 'Wrote: '.$_GET['data']; | |
} | |
shmop_close($memoryHandle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
writer.php
should close$memoryHandle
, not$shm_id
.Here is the right code .