How To Use Shared Memory in PHP Come usare la memoria condivisa in PHP
PHP supports shared memory which can be used to store and retrieve data across processes. PHP supporta memoria condivisa che può essere utilizzata per memorizzare e recuperare i dati tra processi. This is also another alternative way to Questo è anche un altro modo alternativo per communicate between php scripts comunicare tra di script PHP . Normally shared memory is used for caching frequently used data in memory for php scripts on the same server. Normalmente memoria condivisa viene utilizzata per la memorizzazione nella cache frequentemente utilizzati dati in memoria per PHP script sullo stesso server. Let’s see how we can use shared memory with a simple example. Vediamo come si possa utilizzare la memoria condivisa con un semplice esempio.
How to create PHP shared memory and save a variable (array) Come creare PHP memoria condivisa e salvare una variabile (array)
Here is a sample code with comments: Qui c'è un esempio di codice con commenti:
$key = 'mykey'; // Key to store data with //Returns System V IPC key; 'My test' should be replaced by the pathname of an existing file // as per manual. $ key = 'mykey'; / / chiave per memorizzare i dati con / / Restituisce System V IPC chiave; 'Il mio test' dovrebbe essere sostituito con il percorso di un file esistente / / come da manuale. I found that even a non-existent file works fine. Ho trovato che anche un inesistente file funziona bene. // The second argument is project identifier; a single character of your choice $shm_key = ftok('My test','P'); $data = shm_attach($shm_key); // Pointer to shared memory // Sample data to store $test = array("hello","angsuman","chakraborty"); shm_put_var($data,$inmem,$test); // Save the data in shared memory print_r(shm_get_var($data,$mykey)); // Print the saved data shm_detach($data); // Disconnects from shared memory segment; the data remains intact / / Il secondo argomento è identificatore di progetto; un singolo carattere di tua scelta shm_key $ = ftok ( 'La mia prova', 'P'); $ data = shm_attach ($ shm_key); / / Puntatore alla memoria condivisa / / Esempi di dati a negozio prova $ = array ( "ciao", "angsuman", "Chakraborty"); shm_put_var ($ dati, $ inmem, $ prova); / / Salva i dati in memoria condivisa print_r (shm_get_var ($ dati, $ mykey)) / / Stampa la dati salvati shm_detach ($ dati); / / disconnette dal segmento di memoria condivisa; dati rimane intatto
How to fetch data from shared memory in PHP Come recuperare i dati di memoria condivisa in PHP
$key = 'mykey'; $shm_key = ftok('My test','P'); $data = shm_attach($shm_key); print_r(shm_get_var($data,$mykey)); shm_detach($data); $ key = 'mykey'; shm_key $ = ftok ( 'La mia prova', 'P'); $ data = shm_attach ($ shm_key); print_r (shm_get_var ($ dati, $ mykey)); shm_detach ($ dati); Notes: Note:
1. The code has been tested on Linux only. Il codice è stato testato solo su Linux.
2. The arguments to ftok must be same to access the same shared memory from multiple scripts. Le argomentazioni a ftok deve essere lo stesso per accedere alla stessa memoria condivisa da più script. For use in multiple processes within the same script file use __FILE__ as the first argument to ftok(). Per l'uso in più processi all'interno dello stesso file di script utilizzare __FILE__ come primo argomento a ftok ().
Filed under Elencato sotto Enterprise Software Enterprise Software , Headline News Headline News , How To Come , Linux , Open Source Software Software open source , PHP , Programming Programmazione , Web | |
| |
RSS 2.0 RSS 2,0 | |
Trackback this Article | questo articolo |
Email this Article Invia questo articolo
You may also like to read Si può anche leggere come |





November 13th, 2007 at 12:05 pm 13 novembre 2007 alle 12:05 pm
This was an interesting tutorial, nicely done I will have a go at trying this for my self. Questo è stato un interessante tutorial, nicely done avrò uno andare a provare questa procedura per la mia auto.
Regards, Saluti,
Lamonte Harris Lamonte Harris
November 13th, 2007 at 2:53 pm 13 novembre 2007 alle 2:53 pm
It’s fantastic to see a PHP programmer who pays close attention to how much memory they’re using. E 'fantastico vedere un programmatore PHP che paga attenzione alle quantità di memoria che sta utilizzando.
February 20th, 2008 at 3:26 am 20 febbraio 2008, 3:26 am
this is wonderful code and i will test this under my system questo codice è meraviglioso e io questa prova sotto il mio sistema
thanks grazie
June 14th, 2008 at 11:48 am 14 giugno, 2008 11:48 am
where is the code? dove è il codice? I tried opening the page in both Firefox and IE, and code examples seem to be missing ? Ho provato aprire la pagina in entrambi i Firefox e IE, e esempi di codice sembra essere mancante?
June 14th, 2008 at 12:16 pm 14 giugno, 2008 12:16 pm
@Adam Adam @
Thanks. Grazie. I consider myself more as a Java developer Mi considero più come uno sviluppatore Java
June 14th, 2008 at 12:21 pm 14 giugno, 2008 12:21 pm
WordPress 2.5.1 screwed up my code. WordPress 2.5.1 avvitato il mio codice. It is back again. E 'di nuovo indietro. Please refresh the page. Vi preghiamo di aggiornare la pagina.