/** * @return CM_Process */ protected function _getProcess() { return CM_Process::getInstance(); }
/** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testPubSubWithClientUsedInSubClosure() { $process = CM_Process::getInstance(); $process->fork(function () { $redisClient = CM_Service_Manager::getInstance()->getRedis(); $clientCount = 0; while ($clientCount == 0) { $clientCount = $redisClient->publish('foo', 'test'); usleep(50 * 1000); } }); $this->_client->set('check', 'bar'); $response = $this->_client->subscribe('foo', function ($channel, $message) { if ($message == 'test') { return [$channel, $message, $this->_client->get('check')]; } else { return false; } }); $this->assertSame(['foo', 'test', 'bar'], $response); $process->waitForChildren(); }
public function testStartTerminatable() { $process = CM_Process::getInstance(); $forkHandler = $process->fork(function () { $clockworkManager = new CM_Clockwork_Manager(); $clockworkManager->start(); }); usleep(1000000 * 0.1); $process->listenForChildren(); $this->assertSame(true, $process->isRunning($forkHandler->getPid())); posix_kill($forkHandler->getPid(), SIGTERM); usleep(1000000 * 0.1); $process->listenForChildren(); $this->assertSame(false, $process->isRunning($forkHandler->getPid())); }
/** * @return int[] * @throws CM_Exception */ private function _getChildrenPidList() { $psCommand = 'ps axo pid,ppid,args'; $psOutput = CM_Util::exec($psCommand); if (false === preg_match_all('/^\\s*(?<pid>\\d+)\\s+(?<ppid>\\d+)\\s+(?<args>.+)$/m', $psOutput, $matches, PREG_SET_ORDER)) { throw new CM_Exception('Cannot parse ps output `' . $psOutput . '`.'); } $pid = CM_Process::getInstance()->getProcessId(); $pidList = array(); foreach ($matches as $match) { if ($match['ppid'] == $pid && false === strpos($match['args'], $psCommand)) { $pidList[] = (int) $match['pid']; } } return $pidList; }
public function testFreeMemory() { $getMemoryUsage = function () { $pid = CM_Process::getInstance()->getProcessId(); $memory = CM_Util::exec('ps', ['-o', 'rss', '--no-headers', '--pid', $pid]); return (int) $memory; }; $imageOriginal = new CM_File_Image(DIR_TEST_DATA . 'img/test.jpg'); $image = CM_File_Image::createTmp(null, $imageOriginal->read()); $memoryUsage = $getMemoryUsage(); $memoryUsageMaxExpected = $memoryUsage + 20 * 1000; $image->resizeSpecific(3000, 3000); $this->assertGreaterThan($memoryUsageMaxExpected, $getMemoryUsage()); $image->freeMemory(); $this->assertLessThan($memoryUsageMaxExpected, $getMemoryUsage()); $image->validateImage(); }