3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('xreservedmaxstrings', 1000000); //кол-во строк в списке define('xreservedsize', 128); //длинна строки в списке function mkfile($path){ fclose(fopen($path, 'a')); } function putdata($data){ $lock=fopen(__FILE__.'.1.lock', 'w+'); flock($lock, LOCK_EX); //блокируем файл lock для избежания коллизий $i=1; while(true){ if($i<16) $pre=0; //ведущий ноль $dir='./list/'; $list=$dir.$pre.dechex($i).'.list'; //путь к списку if(!file_exists($dir)) mkdir($dir); //если нет папки, создать if(!file_exists($list)) mkfile($list); //если нет списка, создать if($i>255){ return false; echo '<t>[u01] Lists are full.</t>'."\n"; break; } //если заполнены 255 списков, выдать ошибку if(filesize($list)<(xreservedmaxstrings*(xreservedsize+1))){ //если список не заполнен $data.=str_repeat(' ', xreservedsize); $data=substr($data, 0, xreservedsize); file_put_contents($list, $data."\n", LOCK_EX|FILE_APPEND); return true; break; } //записать data в список, дополнив пробелами и обрезав, чтобы data весил xreservedsize байт $i++; $pre=''; } flock($lock, LOCK_UN); fclose($lock); } function getdata($index){ $lock=fopen(__FILE__.'.1.lock', 'w+'); flock($lock, LOCK_EX); //блокируем файл lock для избежания коллизий $listindex=ceil($index/xreservedmaxstrings); //вычисляем номер списка $liststring=($index-($listindex-1)*xreservedmaxstrings); //вычисляем номер строки $pre=''; if($listindex<16) $pre=0; //ведущий ноль $list='./list/'.$pre.dechex($listindex).'.list'; //путь к списку if(!file_exists($list)){ echo '<t>[u02] Requested list is not exists.</t>'."\n"; return false; } //если нет нужного списка, выдать ошибку elseif(filesize($list)<($liststring*(xreservedsize+1))){ echo '<t>[u03] Requested string is not exists.</t>'."\n"; return false; } //если нет нужной строки, выдать ошибку else{ $listf=fopen($list, 'r'); fseek($listf, (($liststring-1)*(xreservedsize+1))); $string=fgets($listf, xreservedsize); return rtrim($string, ' '); } //выдать строку, убрав лишние пробелы flock($lock, LOCK_UN); fclose($lock); } putdata('text'); echo getdata(1);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rLIaa
function name:  (null)
number of ops:  16
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'xreservedmaxstrings'
          2        SEND_VAL                                                 1000000
          3        DO_ICALL                                                 
    4     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'xreservedsize'
          6        SEND_VAL                                                 128
          7        DO_ICALL                                                 
   87     8        INIT_FCALL                                               'putdata'
          9        SEND_VAL                                                 'text'
         10        DO_FCALL                                      0          
         11        INIT_FCALL                                               'getdata'
         12        SEND_VAL                                                 1
         13        DO_FCALL                                      0  $3      
         14        ECHO                                                     $3
         15      > RETURN                                                   1

Function mkfile:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rLIaa
function name:  mkfile
number of ops:  9
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        INIT_FCALL                                               'fclose'
          2        INIT_FCALL                                               'fopen'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'a'
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        DO_ICALL                                                 
    8     8      > RETURN                                                   null

End of function mkfile

Function putdata:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 12
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 74
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
2 jumps found. (Code = 44) Position 1 = 77, Position 2 = 12
Branch analysis from position: 77
Branch analysis from position: 12
Branch analysis from position: 39
Branch analysis from position: 31
Branch analysis from position: 15
filename:       /in/rLIaa
function name:  putdata
number of ops:  85
compiled vars:  !0 = $data, !1 = $lock, !2 = $i, !3 = $pre, !4 = $dir, !5 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'fopen'
          2        SEND_VAL                                                 '%2Fin%2FrLIaa.1.lock'
          3        SEND_VAL                                                 'w%2B'
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !1, $6
   13     6        INIT_FCALL                                               'flock'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 2
          9        DO_ICALL                                                 
   15    10        ASSIGN                                                   !2, 1
   16    11      > JMP                                                      ->76
   17    12    >   IS_SMALLER                                               !2, 16
         13      > JMPZ                                                     ~10, ->15
   18    14    >   ASSIGN                                                   !3, 0
   20    15    >   ASSIGN                                                   !4, '.%2Flist%2F'
   21    16        CONCAT                                           ~13     !4, !3
         17        INIT_FCALL                                               'dechex'
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                         $14     
         20        CONCAT                                           ~15     ~13, $14
         21        CONCAT                                           ~16     ~15, '.list'
         22        ASSIGN                                                   !5, ~16
   23    23        INIT_FCALL                                               'file_exists'
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $18     
         26        BOOL_NOT                                         ~19     $18
         27      > JMPZ                                                     ~19, ->31
   24    28    >   INIT_FCALL                                               'mkdir'
         29        SEND_VAR                                                 !4
         30        DO_ICALL                                                 
   26    31    >   INIT_FCALL                                               'file_exists'
         32        SEND_VAR                                                 !5
         33        DO_ICALL                                         $21     
         34        BOOL_NOT                                         ~22     $21
         35      > JMPZ                                                     ~22, ->39
   27    36    >   INIT_FCALL                                               'mkfile'
         37        SEND_VAR                                                 !5
         38        DO_FCALL                                      0          
   29    39    >   IS_SMALLER                                               255, !2
         40      > JMPZ                                                     ~24, ->44
   30    41    > > RETURN                                                   <false>
   31    42*       ECHO                                                     '%3Ct%3E%5Bu01%5D+Lists+are+full.%3C%2Ft%3E%0A'
   32    43*       JMP                                                      ->77
   35    44    >   INIT_FCALL                                               'filesize'
         45        SEND_VAR                                                 !5
         46        DO_ICALL                                         $25     
         47        FETCH_CONSTANT                                   ~26     'xreservedmaxstrings'
         48        FETCH_CONSTANT                                   ~27     'xreservedsize'
         49        ADD                                              ~28     ~27, 1
         50        MUL                                              ~29     ~26, ~28
         51        IS_SMALLER                                               $25, ~29
         52      > JMPZ                                                     ~30, ->74
   36    53    >   INIT_FCALL                                               'str_repeat'
         54        SEND_VAL                                                 '+'
         55        FETCH_CONSTANT                                   ~31     'xreservedsize'
         56        SEND_VAL                                                 ~31
         57        DO_ICALL                                         $32     
         58        ASSIGN_OP                                     8          !0, $32
   37    59        INIT_FCALL                                               'substr'
         60        SEND_VAR                                                 !0
         61        SEND_VAL                                                 0
         62        FETCH_CONSTANT                                   ~34     'xreservedsize'
         63        SEND_VAL                                                 ~34
         64        DO_ICALL                                         $35     
         65        ASSIGN                                                   !0, $35
   38    66        INIT_FCALL                                               'file_put_contents'
         67        SEND_VAR                                                 !5
         68        CONCAT                                           ~37     !0, '%0A'
         69        SEND_VAL                                                 ~37
         70        SEND_VAL                                                 10
         71        DO_ICALL                                                 
   39    72      > RETURN                                                   <true>
   40    73*       JMP                                                      ->77
   43    74    >   PRE_INC                                                  !2
   44    75        ASSIGN                                                   !3, ''
   16    76    > > JMPNZ                                                    <true>, ->12
   48    77    >   INIT_FCALL                                               'flock'
         78        SEND_VAR                                                 !1
         79        SEND_VAL                                                 3
         80        DO_ICALL                                                 
   49    81        INIT_FCALL                                               'fclose'
         82        SEND_VAR                                                 !1
         83        DO_ICALL                                                 
   51    84      > RETURN                                                   null

End of function putdata

Function getdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 25
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 51
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/rLIaa
function name:  getdata
number of ops:  83
compiled vars:  !0 = $index, !1 = $lock, !2 = $listindex, !3 = $liststring, !4 = $pre, !5 = $list, !6 = $listf, !7 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   55     1        INIT_FCALL                                               'fopen'
          2        SEND_VAL                                                 '%2Fin%2FrLIaa.1.lock'
          3        SEND_VAL                                                 'w%2B'
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !1, $8
   56     6        INIT_FCALL                                               'flock'
          7        SEND_VAR                                                 !1
          8        SEND_VAL                                                 2
          9        DO_ICALL                                                 
   58    10        INIT_FCALL                                               'ceil'
         11        FETCH_CONSTANT                                   ~11     'xreservedmaxstrings'
         12        DIV                                              ~12     !0, ~11
         13        SEND_VAL                                                 ~12
         14        DO_ICALL                                         $13     
         15        ASSIGN                                                   !2, $13
   59    16        SUB                                              ~15     !2, 1
         17        FETCH_CONSTANT                                   ~16     'xreservedmaxstrings'
         18        MUL                                              ~17     ~15, ~16
         19        SUB                                              ~18     !0, ~17
         20        ASSIGN                                                   !3, ~18
   60    21        ASSIGN                                                   !4, ''
   61    22        IS_SMALLER                                               !2, 16
         23      > JMPZ                                                     ~21, ->25
   62    24    >   ASSIGN                                                   !4, 0
   64    25    >   CONCAT                                           ~23     '.%2Flist%2F', !4
         26        INIT_FCALL                                               'dechex'
         27        SEND_VAR                                                 !2
         28        DO_ICALL                                         $24     
         29        CONCAT                                           ~25     ~23, $24
         30        CONCAT                                           ~26     ~25, '.list'
         31        ASSIGN                                                   !5, ~26
   66    32        INIT_FCALL                                               'file_exists'
         33        SEND_VAR                                                 !5
         34        DO_ICALL                                         $28     
         35        BOOL_NOT                                         ~29     $28
         36      > JMPZ                                                     ~29, ->40
   67    37    >   ECHO                                                     '%3Ct%3E%5Bu02%5D+Requested+list+is+not+exists.%3C%2Ft%3E%0A'
   68    38      > RETURN                                                   <false>
         39*       JMP                                                      ->75
   70    40    >   INIT_FCALL                                               'filesize'
         41        SEND_VAR                                                 !5
         42        DO_ICALL                                         $30     
         43        FETCH_CONSTANT                                   ~31     'xreservedsize'
         44        ADD                                              ~32     ~31, 1
         45        MUL                                              ~33     !3, ~32
         46        IS_SMALLER                                               $30, ~33
         47      > JMPZ                                                     ~34, ->51
   71    48    >   ECHO                                                     '%3Ct%3E%5Bu03%5D+Requested+string+is+not+exists.%3C%2Ft%3E%0A'
   72    49      > RETURN                                                   <false>
         50*       JMP                                                      ->75
   75    51    >   INIT_FCALL                                               'fopen'
         52        SEND_VAR                                                 !5
         53        SEND_VAL                                                 'r'
         54        DO_ICALL                                         $35     
         55        ASSIGN                                                   !6, $35
   76    56        INIT_FCALL                                               'fseek'
         57        SEND_VAR                                                 !6
         58        SUB                                              ~37     !3, 1
         59        FETCH_CONSTANT                                   ~38     'xreservedsize'
         60        ADD                                              ~39     ~38, 1
         61        MUL                                              ~40     ~37, ~39
         62        SEND_VAL                                                 ~40
         63        DO_ICALL                                                 
   77    64        INIT_FCALL                                               'fgets'
         65        SEND_VAR                                                 !6
         66        FETCH_CONSTANT                                   ~42     'xreservedsize'
         67        SEND_VAL                                                 ~42
         68        DO_ICALL                                         $43     
         69        ASSIGN                                                   !7, $43
   78    70        INIT_FCALL                                               'rtrim'
         71        SEND_VAR                                                 !7
         72        SEND_VAL                                                 '+'
         73        DO_ICALL                                         $45     
         74      > RETURN                                                   $45
   81    75*       INIT_FCALL                                               'flock'
         76*       SEND_VAR                                                 !1
         77*       SEND_VAL                                                 3
         78*       DO_ICALL                                                 
   82    79*       INIT_FCALL                                               'fclose'
         80*       SEND_VAR                                                 !1
         81*       DO_ICALL                                                 
   84    82*     > RETURN                                                   null

End of function getdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.58 ms | 1415 KiB | 46 Q