3v4l.org

run code in 300+ PHP versions simultaneously
<?php // This is a proof-of-concept for the PHP-Memory-Bug. // This is a well known PHP-Behavior, this script will test if this bug // can be solved using "array-key-recycling". // Switch this to proof //$bLinear = FALSE; // Array-Keys are recycled $bLinear = TRUE; // Array-Keys just increment -> Bug! // Some Constants $loops = 1000; $start = 0; $size = 1000; $payload = "testing..."; $mem_limit = "5M"; // Set Memory-Limit, define memory_get_usage for older versions ini_set("memory_limit",$mem_limit); if(!function_exists("memory_get_usage")){ function memory_get_usage() { $output = Array(); $pid = getmypid(); exec("ps -o rss -p $pid", $output); return $output[1] *1024; } } // Output-Function function sEcho($message = ""){ echo date("d.m.Y H:i:s")." ".number_format(memory_get_usage())." ".$message."\n"; } sEcho("Starting"); // Main loop for($k=0;$k<$loops;$k++){ // Recycle or use new array-key $multiplier = 1; if($bLinear) $multiplier = $k; // Get some Data - i.e. from MySQL $arData = Array(); sEcho("filling ".$k); for($i=$start*$multiplier;$i<($size*$multiplier)+$size;$i++){ $arData["a"][$i]["c"] = $payload; $arData["b"][$i]["d"] = $payload; } sEcho("filled ".$k); // Do Some Stuff... // Free data again unset($arData); // This will not free the used array-keys. sEcho("unset ".$k); } sEcho("Done");
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 21
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 32
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 21
Branch analysis from position: 57
Branch analysis from position: 21
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 32
Branch analysis from position: 45
Branch analysis from position: 32
Branch analysis from position: 24
Branch analysis from position: 16
filename:       /in/B6BZC
function name:  (null)
number of ops:  61
compiled vars:  !0 = $bLinear, !1 = $loops, !2 = $start, !3 = $size, !4 = $payload, !5 = $mem_limit, !6 = $k, !7 = $multiplier, !8 = $arData, !9 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ASSIGN                                                   !0, <true>
   12     1        ASSIGN                                                   !1, 1000
   13     2        ASSIGN                                                   !2, 0
   14     3        ASSIGN                                                   !3, 1000
   15     4        ASSIGN                                                   !4, 'testing...'
   16     5        ASSIGN                                                   !5, '5M'
   19     6        INIT_FCALL                                               'ini_set'
          7        SEND_VAL                                                 'memory_limit'
          8        SEND_VAR                                                 !5
          9        DO_ICALL                                                 
   20    10        INIT_FCALL                                               'function_exists'
         11        SEND_VAL                                                 'memory_get_usage'
         12        DO_ICALL                                         $17     
         13        BOOL_NOT                                         ~18     $17
         14      > JMPZ                                                     ~18, ->16
   21    15    >   DECLARE_FUNCTION                                         'memory_get_usage'
   34    16    >   INIT_FCALL                                               'secho'
         17        SEND_VAL                                                 'Starting'
         18        DO_FCALL                                      0          
   37    19        ASSIGN                                                   !6, 0
         20      > JMP                                                      ->55
   40    21    >   ASSIGN                                                   !7, 1
   41    22      > JMPZ                                                     !0, ->24
         23    >   ASSIGN                                                   !7, !6
   44    24    >   ASSIGN                                                   !8, <array>
   45    25        INIT_FCALL                                               'secho'
         26        CONCAT                                           ~24     'filling+', !6
         27        SEND_VAL                                                 ~24
         28        DO_FCALL                                      0          
   46    29        MUL                                              ~26     !2, !7
         30        ASSIGN                                                   !9, ~26
         31      > JMP                                                      ->41
   47    32    >   FETCH_DIM_W                                      $28     !8, 'a'
         33        FETCH_DIM_W                                      $29     $28, !9
         34        ASSIGN_DIM                                               $29, 'c'
         35        OP_DATA                                                  !4
   48    36        FETCH_DIM_W                                      $31     !8, 'b'
         37        FETCH_DIM_W                                      $32     $31, !9
         38        ASSIGN_DIM                                               $32, 'd'
         39        OP_DATA                                                  !4
   46    40        PRE_INC                                                  !9
         41    >   MUL                                              ~35     !3, !7
         42        ADD                                              ~36     ~35, !3
         43        IS_SMALLER                                               !9, ~36
         44      > JMPNZ                                                    ~37, ->32
   50    45    >   INIT_FCALL                                               'secho'
         46        CONCAT                                           ~38     'filled+', !6
         47        SEND_VAL                                                 ~38
         48        DO_FCALL                                      0          
   55    49        UNSET_CV                                                 !8
   56    50        INIT_FCALL                                               'secho'
         51        CONCAT                                           ~40     'unset+', !6
         52        SEND_VAL                                                 ~40
         53        DO_FCALL                                      0          
   37    54        PRE_INC                                                  !6
         55    >   IS_SMALLER                                               !6, !1
         56      > JMPNZ                                                    ~43, ->21
   59    57    >   INIT_FCALL                                               'secho'
         58        SEND_VAL                                                 'Done'
         59        DO_FCALL                                      0          
         60      > RETURN                                                   1

Function %00memory_get_usage%2Fin%2FB6BZC%3A21%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B6BZC
function name:  memory_get_usage
number of ops:  14
compiled vars:  !0 = $output, !1 = $pid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                   !0, <array>
   23     1        INIT_FCALL                                               'getmypid'
          2        DO_ICALL                                         $3      
          3        ASSIGN                                                   !1, $3
   24     4        INIT_FCALL                                               'exec'
          5        NOP                                                      
          6        FAST_CONCAT                                      ~5      'ps+-o+rss+-p+', !1
          7        SEND_VAL                                                 ~5
          8        SEND_REF                                                 !0
          9        DO_ICALL                                                 
   25    10        FETCH_DIM_R                                      ~7      !0, 1
         11        MUL                                              ~8      ~7, 1024
         12      > RETURN                                                   ~8
   26    13*     > RETURN                                                   null

End of function %00memory_get_usage%2Fin%2FB6BZC%3A21%240

Function secho:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B6BZC
function name:  sEcho
number of ops:  16
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV_INIT                                        !0      ''
   31     1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'd.m.Y+H%3Ai%3As'
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      $1, '+'
          5        INIT_FCALL                                               'number_format'
          6        INIT_FCALL                                               'memory_get_usage'
          7        DO_ICALL                                         $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                         $4      
         10        CONCAT                                           ~5      ~2, $4
         11        CONCAT                                           ~6      ~5, '+'
         12        CONCAT                                           ~7      ~6, !0
         13        CONCAT                                           ~8      ~7, '%0A'
         14        ECHO                                                     ~8
   32    15      > RETURN                                                   null

End of function secho

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.26 ms | 1407 KiB | 32 Q