/** * Test the whole transport */ public function testAll() { $sTestVal = uniqid(); $sTestKey = (int) microtime(true); $sTestTestKey = md5($sTestKey); $this->assertFalse($this->_object->read($sTestKey)); $this->assertInstanceOf($this->_sTestClass, $this->_object->write($sTestKey, $sTestVal)); $this->assertInstanceOf($this->_sTestClass, $this->_object->write($sTestTestKey, $sTestVal)); $this->assertEquals($sTestVal, $this->_object->read($sTestKey)); $this->assertInstanceOf($this->_sTestClass, $this->_object->delete($sTestKey)); $this->assertFalse($this->_object->read($sTestKey)); $this->assertEquals($sTestVal, $this->_object->read($sTestTestKey)); $this->assertInstanceOf($this->_sTestClass, $this->_object->free()); $this->assertFalse($this->_object->read($sTestTestKey)); }
/** * Run * * @param array $aMethods Methods to execute * * @return $this */ public function run(array $aMethods = array()) { $this->resetStats(); if (count($this->_aStack) === 1 or $this->_iThreads === 1 or $this->_oTransport instanceof TransportInterface === false) { foreach (array_keys($this->_aStack) as $iStack) { $this->_execute($aMethods, $iStack); $this->_iFinished++; } } else { foreach (array_keys($this->_aStack) as $iStack) { $iChildren = count($this->_aProc); if ($iChildren < $this->_iThreads or $this->_iThreads === 0) { $this->_aProc[$iStack] = pcntl_fork(); if ($this->_aProc[$iStack] === -1) { unset($this->_aProc[$iStack]); } elseif ($this->_aProc[$iStack] === 0) { // this is the child-process, it will exit after execution $this->_execute($aMethods, $iStack); $this->_oTransport->write($iStack, gzcompress(serialize($this->_aStack[$iStack]), 1)); exit; } } while (count($this->_aProc) >= $this->_iThreads and $this->_iThreads !== 0) { $this->_wait()->_read(); } } $this->_wait(true)->_read(); $this->_oTransport->free(); } return $this; }