RE: [PHP] Shared Memory

From: Date: Sat, 14 Oct 2000 21:18:59 +0000
Subject: RE: [PHP] Shared Memory
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20169@lists.php.net to get a copy of this message
PHP has several problems related to shared memory. 1) PHP sticks a php-signature on a shared memory block, last time I checked you could not just 'dump' data in a block. So, in order to communicate with a C program you'd need to use the 'php method' of reading and writing shared memory. (Which can be quite a PITA, since you'd have to dig into the php sourcecode to figure out the block layout and encoding.) 2) Synchronisation. Usually, when dealing with a shared piece of memory there is some kind of synchronisation, and very often that is done using semaphores. Now, when you enter a WAIT state the process is suspended, and if the process waiting is never signalled the process *stays* suspended. PHP execution timers do *not* terminate processes that are in suspended state. This is a very nasty effect that makes semaphores a very dangerous tool in php. Deadlocks are not a good thing. So, if you're absolutely sure what you're doing, shared memory may be a very fast way of transferring data. But I would advise using alternative methods of communication if you want to communicate with other php scripts or other processes. (For example, pipes or unix domainsockets) -Sander > > When you create a shared memory segment the system needs a way to identify > your shared memory segment from all other shared memory segments > out there. > This is accomplished by assigning each shared memory segment an identifier > of sorts. The system then uses that identifier as a pointer to your shared > memory segment. The key should be a unique number so that the > system doesn't > confuse your shared memory segment with someone else's memory segment. > The access modes for shared memory are the same as for files, ex 644 would > mean that the shared memory segment is world readable but only the owner > (person who created the memory segment) can write to it. > Shared memory is the fastest IPC (Inter Process Communication) > method which > means its generally used to quickly transfer data between > separate process', > ex. I use shared memory to transfer date between a C daemon running on a > system and a php client. > > > Ilia Alshanetsky > iliaa@home.com > > > > ----- Original Message ----- > From: "Jeff Davis" <jdavis@wasabimg.com> > To: <php-general@lists.php.net> > Sent: Saturday, October 14, 2000 4:05 PM > Subject: [PHP] Shared Memory > > > > I read the following at the php.net manual: > > > > shm_open() takes 4 parameters: key, which is the system's id for the > > shared memory block, this parameter can be passed as a decimal or hex. > > > > I am interested in using shared memory, but I don't know what to supply > > for the key. I also don't know how the access mode (ie 0644) works with > > memory. What kinds of situations might shared memory be used for? Is it > > to hold data from one script to the next, or should it not be sued for > > that? > > > > Thanks, > > Jeff Davis

« previous php.general (#20169) next »