Zugesichertes und tatsächlich nutzbares memory_limit

Um zu verifizieren, dass wir auch tatsächlich diese 256MB Arbeitsspeicher zur Verfügung stellen, können Sie folgendes Skript verwenden:

<?php
$before = memory_get_usage();
$store = array();
while(true){
    //generate approx. 1MB
    for ($j = 0; $j<1024; $j++) {
        //generate approx. 1kB
        for ($i = 0; $i<10; $i++) {
            $store[] = 'abcdefghijklmnopqstuvwxy'; //4*25bytes assuming unicode
        }
    }
    $after = memory_get_usage();
    $script = ($after - $before)/1024/1024;
    $total = ($after)/1024/1024;
    echo  "script: $script, total: $total<br/>";
}
?>

Legen Sie dieses Skript in Ihrem Webspace ab und rufen es über HTTP auf.

Sie erhalten nun folgenden oder ähnlichen Output:

script: 1.54736328125, total: 1.60482025146
script: 3.09492111206, total: 3.15237808228
script: 4.57940673828, total: 4.6368637085
script: 6.18883132935, total: 6.24628829956
script: 7.67325210571, total: 7.73070907593
script: 9.15767288208, total: 9.21512985229
script: 10.8920936584, total: 10.9495506287
script: 12.3765144348, total: 12.433971405
script: 13.8609352112, total: 13.9183921814
script: 15.3453559875, total: 15.4028129578
script: 16.8297767639, total: 16.8872337341
script: 18.3141975403, total: 18.3716545105
script: 20.2986183167, total: 20.3560752869
(...)
script: 100.4884758, total: 100.54593277
script: 101.972896576, total: 102.030353546
script: 103.457317352, total: 103.514774323
script: 104.941738129, total: 104.999195099
script: 106.426151276, total: 106.483608246
script: 107.910572052, total: 107.968029022
script: 109.394992828, total: 109.452449799
script: 110.879413605, total: 110.936870575
script: 112.363834381, total: 112.421291351
script: 113.848255157, total: 113.905712128
script: 115.332675934, total: 115.390132904
script: 116.81709671, total: 116.87455368
script: 118.301517487, total: 118.358974457
script: 119.785938263, total: 119.843395233
script: 121.270359039, total: 121.32781601
script: 122.754779816, total: 122.812236786
script: 124.239200592, total: 124.296657562
script: 125.723621368, total: 125.781078339
script: 127.208042145, total: 127.265499115

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes) in /var/www/.../memusage.php on line 17

Es konnten also tatsächlich ca. 256MB an Arbeitsspeicher belegt werden, bevor PHP die weitere Verarbeitung unterbunden hat.

Benötigen Sie mehr als 256MB RAM, so setzen Sie sich bitte mit unserem Support in Verbindung.