-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added function kilobytes_to_human_readable
added Conf functions
- Loading branch information
1 parent
d3dabac
commit a37ab4c
Showing
4 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the PhPease package. | ||
* | ||
* (c) Timo Reith <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace PhPease\Conf; | ||
|
||
/** | ||
* get memory limit in kilobyte | ||
* @return false|float|int|string | ||
*/ | ||
function get_memory_limit() { | ||
$memory_limit = ini_get('memory_limit'); | ||
if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) { | ||
if ($matches[2] == 'M') { | ||
$memory_limit = $matches[1] * 1024; // nnnM -> nnn MB | ||
} else if ($matches[2] == 'K') { | ||
$memory_limit = $matches[1]; // nnnK -> nnn KB | ||
} else if ($matches[2] == 'G') { | ||
$memory_limit = $matches[1] * 1024 * 1024; // nnnG -> nnn GB | ||
} | ||
} | ||
return $memory_limit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php declare(strict_types=1); | ||
use PHPUnit\Framework\TestCase; | ||
use function PhPease\Conf\get_memory_limit; | ||
use function PhPease\Convert\kilobytes_to_human_readable; | ||
|
||
final class ConfTest extends TestCase | ||
{ | ||
public function test_get_memory_limit() | ||
{ | ||
ini_set('memory_limit', '128M'); | ||
|
||
$memLimit = get_memory_limit(); | ||
|
||
$this->assertEquals(131072, $memLimit); | ||
$this->assertEquals('128.00 MB', kilobytes_to_human_readable($memLimit)); | ||
} | ||
} |