PHP shared memory implementation of php memory queue

  
 

<?php /** *PHP
Circular Memory Queue Implementation with Shared Memory* Supports multiple processes, supports storage of various data types* Note: Complete enqueue or dequeue operation as soon as possible Use unset() to release the critical section * /class SHMQueue { private $maxQSize = 0; //queue maximum length private $front = 0; //head pointer private $rear = 0; //tail pointer private $blockSize = 256; //block size (byte) private $memSize = 25600; //maximum shared memory (byte) private $shmId = 0; private $filePtr = './shmq.ptr'; private $semId = 0; public Function __construct() { $shmkey = ftok(__FILE__, 't'); $this->shmId = shmop_open($shmkey, "c", 0644, $this->memSize ); $this->maxQSize = $this->memSize /$this->blockSize; //Request a semaphore $this->semId = sem_get($shmkey, 1); sem_acquire($this->semId); //Apply to enter Critical section $this->init(); } private function init() { if ( file_exists($this->filePtr) ){ $contents = file_get_contents($this->filePtr); $data = explode( '

Copyright © Windows knowledge All Rights Reserved