function checkMemory()
{
    $limit = 9;
    $recommended = 16;
    $maxMemory = null;
    $msg = '';
    $cssClass = '';
    $result = checkPHPMemory($limit, $recommended, $maxMemory);
    switch ($result) {
        case INSTALLUTIL_MEMORY_NO_LIMIT:
            $msg = "OK (No Limit)";
            $cssClass = "done";
            break;
        case INSTALLUTIL_MEMORY_UNLIMITED:
            $msg = "OK (Unlimited)";
            $cssClass = "done";
            break;
        case INSTALLUTIL_MEMORY_HARD_LIMIT_FAIL:
            $msg = "Warning at least {$limit}M required ({$maxMemory} available, Recommended {$recommended}M)";
            $cssClass = "error";
            break;
        case INSTALLUTIL_MEMORY_SOFT_LIMIT_FAIL:
            $msg = "OK (Recommended {$recommended}M)";
            $cssClass = "pending";
            break;
        case INSTALLUTIL_MEMORY_OK:
            $msg = "OK";
            $cssClass = "done";
            break;
    }
    $msg = "<b class='{$cssClass}'>" . $msg . "</b>";
    return $msg;
}
Esempio n. 2
0
 /**
  * Test method for checkPHPMemory() in installUtil.php
  */
 public function testCheckPHPMemory()
 {
     $memory = "24M";
     $this->assertEquals(checkPHPMemory(5, 10, $memory), INSTALLUTIL_MEMORY_OK, 'Should return INSTALLUTIL_MEMORY_OK');
     $memory = "12M";
     $this->assertEquals(checkPHPMemory(5, 16, $memory), INSTALLUTIL_MEMORY_SOFT_LIMIT_FAIL, 'Should return INSTALLUTIL_MEMORY_SOFT_LIMIT_FAIL');
     $memory = "4M";
     $this->assertEquals(checkPHPMemory(5, 16, $memory), INSTALLUTIL_MEMORY_HARD_LIMIT_FAIL, 'Should return INSTALLUTIL_MEMORY_HARD_LIMIT_FAIL');
     $memory = "-1";
     $this->assertEquals(checkPHPMemory(5, 16, $memory), INSTALLUTIL_MEMORY_UNLIMITED, 'Should return INSTALLUTIL_MEMORY_UNLIMITED');
     $memory = "";
     $this->assertEquals(checkPHPMemory(5, 16, $memory), INSTALLUTIL_MEMORY_NO_LIMIT, 'Should return INSTALLUTIL_MEMORY_NO_LIMIT');
     $actualMaxMem = ini_get('memory_limit');
     $actualMemInt = (int) $actualMaxMem;
     if ($actualMemInt > 0) {
         $softLimit = $actualMemInt + 1;
         $hardLimit = $actualMemInt - 1;
         $this->assertEquals(checkPHPMemory($hardLimit, $softLimit), INSTALLUTIL_MEMORY_SOFT_LIMIT_FAIL, 'Should return INSTALLUTIL_MEMORY_OK');
         $memory = null;
         $this->assertEquals(checkPHPMemory($hardLimit, $softLimit, $memory), INSTALLUTIL_MEMORY_SOFT_LIMIT_FAIL, 'Should return INSTALLUTIL_MEMORY_OK');
         $this->assertEquals($memory, $actualMaxMem, "Should return memory value");
     }
 }