3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_dump(ini_get('memory_limit')); echo "\n"; $shallowFiberFactoryFiber = new Fiber(function(): void { $fiberNumber = 0; while (true) { $res = new Fiber(function (\Closure $fx) use (&$fiberNumber): void { $res = $fx($fiberNumber++); Fiber::suspend($res); }); Fiber::suspend($res); } }); $shallowFiberFactoryFx = function () use ($shallowFiberFactoryFiber): \Fiber { return !$shallowFiberFactoryFiber->isStarted() ? $shallowFiberFactoryFiber->start() : $shallowFiberFactoryFiber->resume(); }; $i = 0; $fx = function (int $fiberNumber) use ($shallowFiberFactoryFx): void { $res = array_map(function ($str) use ($shallowFiberFactoryFx, $fiberNumber) { global $i, $fx; $i++; // log/debug execution if (($i % 1_000) === 0) { var_dump($i . ' at fiber: ' . $fiberNumber); } // terminating cond if ($i > 50_000) { return 'finished at fiber: ' . $fiberNumber; } // recurse - every 2k reentry unroll the machine stack using Fiber return ($i % 2_000) === 0 ? $shallowFiberFactoryFx()->start($fx)[0] : $fx($fiberNumber); }, ['x']); Fiber::suspend($res); }; $res = $shallowFiberFactoryFx()->start($fx); echo "\n"; print_r($res);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Jjrr
function name:  (null)
number of ops:  30
compiled vars:  !0 = $shallowFiberFactoryFiber, !1 = $shallowFiberFactoryFx, !2 = $i, !3 = $fx, !4 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'ini_get'
          2        SEND_VAL                                                 'memory_limit'
          3        DO_ICALL                                         $5      
          4        SEND_VAR                                                 $5
          5        DO_ICALL                                                 
    4     6        ECHO                                                     '%0A'
    6     7        NEW                                              $7      'Fiber'
          8        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
   17     9        SEND_VAL_EX                                              ~8
    6    10        DO_FCALL                                      0          
         11        ASSIGN                                                   !0, $7
   19    12        DECLARE_LAMBDA_FUNCTION                          ~11     [1]
         13        BIND_LEXICAL                                             ~11, !0
         14        ASSIGN                                                   !1, ~11
   25    15        ASSIGN                                                   !2, 0
   26    16        DECLARE_LAMBDA_FUNCTION                          ~14     [2]
         17        BIND_LEXICAL                                             ~14, !1
         18        ASSIGN                                                   !3, ~14
   50    19        INIT_DYNAMIC_CALL                                        !1
         20        DO_FCALL                                      0  $16     
         21        INIT_METHOD_CALL                                         $16, 'start'
         22        SEND_VAR_EX                                              !3
         23        DO_FCALL                                      0  $17     
         24        ASSIGN                                                   !4, $17
   52    25        ECHO                                                     '%0A'
   53    26        INIT_FCALL                                               'print_r'
         27        SEND_VAR                                                 !4
         28        DO_ICALL                                                 
         29      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 2
Branch analysis from position: 12
Branch analysis from position: 2
filename:       /in/0Jjrr
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $fiberNumber, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, 0
    8     1      > JMP                                                      ->11
    9     2    >   NEW                                              $3      'Fiber'
          3        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          4        BIND_LEXICAL                                             ~4, !0
   13     5        SEND_VAL_EX                                              ~4
    9     6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $3
   15     8        INIT_STATIC_METHOD_CALL                                  'Fiber', 'suspend'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0          
    8    11    > > JMPNZ                                                    <true>, ->2
   17    12    > > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Jjrr
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $fx, !1 = $fiberNumber, !2 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   10     2        INIT_DYNAMIC_CALL                                        !0
          3        POST_INC                                         ~3      !1
          4        SEND_VAL_EX                                              ~3
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !2, $4
   12     7        INIT_STATIC_METHOD_CALL                                  'Fiber', 'suspend'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0          
   13    10      > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Jjrr
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $shallowFiberFactoryFiber
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   BIND_STATIC                                              !0
   20     1        INIT_METHOD_CALL                                         !0, 'isStarted'
          2        DO_FCALL                                      0  $1      
          3        BOOL_NOT                                         ~2      $1
          4      > JMPZ                                                     ~2, ->9
   21     5    >   INIT_METHOD_CALL                                         !0, 'start'
          6        DO_FCALL                                      0  $3      
          7        QM_ASSIGN                                        ~4      $3
          8      > JMP                                                      ->12
   22     9    >   INIT_METHOD_CALL                                         !0, 'resume'
         10        DO_FCALL                                      0  $5      
         11        QM_ASSIGN                                        ~4      $5
         12    >   VERIFY_RETURN_TYPE                                       ~4
         13      > RETURN                                                   ~4
   23    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0Jjrr
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $fiberNumber, !1 = $shallowFiberFactoryFx, !2 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   27     2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          4        BIND_LEXICAL                                             ~3, !1
          5        BIND_LEXICAL                                             ~3, !0
   45     6        SEND_VAL                                                 ~3
          7        SEND_VAL                                                 <array>
   27     8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !2, $4
   47    10        INIT_STATIC_METHOD_CALL                                  'Fiber', 'suspend'
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0          
   48    13      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 29
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/0Jjrr
function name:  {closure}
number of ops:  35
compiled vars:  !0 = $str, !1 = $shallowFiberFactoryFx, !2 = $fiberNumber, !3 = $i, !4 = $fx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   28     3        BIND_GLOBAL                                              !3, 'i'
          4        BIND_GLOBAL                                              !4, 'fx'
   29     5        PRE_INC                                                  !3
   32     6        MOD                                              ~6      !3, 1000
          7        IS_IDENTICAL                                             ~6, 0
          8      > JMPZ                                                     ~7, ->14
   33     9    >   INIT_FCALL                                               'var_dump'
         10        CONCAT                                           ~8      !3, '+at+fiber%3A+'
         11        CONCAT                                           ~9      ~8, !2
         12        SEND_VAL                                                 ~9
         13        DO_ICALL                                                 
   37    14    >   IS_SMALLER                                               50000, !3
         15      > JMPZ                                                     ~11, ->18
   38    16    >   CONCAT                                           ~12     'finished+at+fiber%3A+', !2
         17      > RETURN                                                   ~12
   42    18    >   MOD                                              ~13     !3, 2000
         19        IS_IDENTICAL                                             ~13, 0
         20      > JMPZ                                                     ~14, ->29
   43    21    >   INIT_DYNAMIC_CALL                                        !1
         22        DO_FCALL                                      0  $15     
         23        INIT_METHOD_CALL                                         $15, 'start'
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0  $16     
         26        FETCH_DIM_R                                      ~17     $16, 0
         27        QM_ASSIGN                                        ~18     ~17
         28      > JMP                                                      ->33
   44    29    >   INIT_DYNAMIC_CALL                                        !4
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0  $19     
         32        QM_ASSIGN                                        ~18     $19
         33    > > RETURN                                                   ~18
   45    34*     > RETURN                                                   null

End of Dynamic Function 0

End of Dynamic Function 2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.45 ms | 1014 KiB | 17 Q