3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Handles Memcache Sessions * * @property Memcache $pool Memcache Object */ class MemcacheSessionModule /*implements \SessionHandlerInterface */ { const UNIX_PREFIX = 'unix://'; const FILE_PREFIX = 'file://'; const TCP_PREFIX = 'tcp://'; const SCHEME_FILE = 'file'; const SCHEME_TCP = 'tcp'; const SCHEME_UNIX = 'unix'; const ZERO_PORT = ':0'; /** * Our Memcache Pool * @var Memcache */ private $pool; public function __construct() { $this->pool = new Memcache; } public function close() { return $this->pool->close(); } public function destroy($sessionId) { } public function gc($maxLifetime) { } public function open($savePath, $name) { $serverList = self::parseSavePath($savePath); if (!$serverList) { return false; } foreach ($serverList as $serverInfo) { var_dump($serverInfo); $this->pool->addserver( $serverInfo['host'], $serverInfo['port'], $serverInfo['persistent'], $serverInfo['weight'], $serverInfo['timeout'], $serverInfo['retry_interval'] ); } return true; } public function read($sessionId) { } public function write($sessionId, $data) { } private static function parseSavePath($savePath) { if (empty($savePath)) { trigger_error( "Failed to parse session.save_path (empty save_path)", E_WARNING); return false; } $serverList = explode(',', $savePath); $return = array(); foreach ($serverList as $url) { $url = strtolower($url); // Swap unix:// to file:// for parse_url if (substr($url, 0, strlen(self::UNIX_PREFIX)) === self::UNIX_PREFIX) { $url = self::FILE_PREFIX . substr($url, strlen(self::UNIX_PREFIX)); } $parsedUrlData = parse_url($url); if (!$parsedUrlData) { trigger_error("Failed to parse session.save_path (unable to parse " . "url, url was '" . $url . "')", E_WARNING); return false; } // Init optional values $serverInfo = array( 'persistent' => null, 'weight' => null, 'timeout' => null, 'retry_interval' => null ); switch ($parsedUrlData['scheme']) { case self::SCHEME_FILE: if (substr($parsedUrlData['path'], -2) === self::ZERO_PORT) { $parsedUrlData['path'] = substr($parsedUrlData['path'], 0, -2); } $serverInfo['host'] = self::UNIX_PREFIX . $parsedUrlData['path']; $serverInfo['port'] = 0; break; case self::SCHEME_TCP: $serverInfo['host'] = self::TCP_PREFIX . $parsedUrlData['host']; if (array_key_exists('port', $parsedUrlData)) { $serverInfo['port'] = $parsedUrlData['port']; } else { $serverInfo['port'] = (int)ini_get('memcache.default_port'); } break; default: trigger_error("Failed to parse session.save_path (unknown protocol," . " url was '" . $url . "')", E_WARNING); return false; } if (array_key_exists('query', $parsedUrlData)) { $optionList = array(); parse_str($parsedUrlData['query'], $optionList); if (count($optionList) > 0) { foreach ($optionList as $key => $value) { switch ($key) { case 'persistent': $serverInfo[$key] = (bool)$value; break; case 'weight': case 'timeout': case 'retry_interval': $serverInfo[$key] = (int)$value; break; } } } } $return[] = $serverInfo; } return $return; } } $session = new MemcacheSessionModule; $session->open('unix:///var/run/memcache.sock?weight=123,tcp://127.0.0.1:11211?weight=1&persistent=1&timeout=4');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kDOjZ
function name:  (null)
number of ops:  7
compiled vars:  !0 = $session
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  153     0  E >   NEW                                              $1      'MemcacheSessionModule'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
  154     3        INIT_METHOD_CALL                                         !0, 'open'
          4        SEND_VAL_EX                                              'unix%3A%2F%2F%2Fvar%2Frun%2Fmemcache.sock%3Fweight%3D123%2Ctcp%3A%2F%2F127.0.0.1%3A11211%3Fweight%3D1%26persistent%3D1%26timeout%3D4'
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Class MemcacheSessionModule:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kDOjZ
function name:  __construct
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $1      'Memcache'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'pool'
          3        OP_DATA                                                  $1
   29     4      > RETURN                                                   null

End of function __construct

Function close:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kDOjZ
function name:  close
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                      ~0      'pool'
          1        INIT_METHOD_CALL                                         ~0, 'close'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   33     4*     > RETURN                                                   null

End of function close

Function destroy:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kDOjZ
function name:  destroy
number of ops:  2
compiled vars:  !0 = $sessionId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1      > RETURN                                                   null

End of function destroy

Function gc:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kDOjZ
function name:  gc
number of ops:  2
compiled vars:  !0 = $maxLifetime
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1      > RETURN                                                   null

End of function gc

Function open:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 36
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 36
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/kDOjZ
function name:  open
number of ops:  39
compiled vars:  !0 = $savePath, !1 = $name, !2 = $serverList, !3 = $serverInfo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   44     2        INIT_STATIC_METHOD_CALL                                  'parseSavePath'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !2, $4
   45     6        BOOL_NOT                                         ~6      !2
          7      > JMPZ                                                     ~6, ->9
   46     8    > > RETURN                                                   <false>
   48     9    > > FE_RESET_R                                       $7      !2, ->36
         10    > > FE_FETCH_R                                               $7, !3, ->36
   49    11    >   INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                                 
   50    14        FETCH_OBJ_R                                      ~9      'pool'
         15        INIT_METHOD_CALL                                         ~9, 'addserver'
         16        CHECK_FUNC_ARG                                           
   51    17        FETCH_DIM_FUNC_ARG                               $10     !3, 'host'
         18        SEND_FUNC_ARG                                            $10
         19        CHECK_FUNC_ARG                                           
   52    20        FETCH_DIM_FUNC_ARG                               $11     !3, 'port'
         21        SEND_FUNC_ARG                                            $11
         22        CHECK_FUNC_ARG                                           
   53    23        FETCH_DIM_FUNC_ARG                               $12     !3, 'persistent'
         24        SEND_FUNC_ARG                                            $12
         25        CHECK_FUNC_ARG                                           
   54    26        FETCH_DIM_FUNC_ARG                               $13     !3, 'weight'
         27        SEND_FUNC_ARG                                            $13
         28        CHECK_FUNC_ARG                                           
   55    29        FETCH_DIM_FUNC_ARG                               $14     !3, 'timeout'
         30        SEND_FUNC_ARG                                            $14
         31        CHECK_FUNC_ARG                                           
   56    32        FETCH_DIM_FUNC_ARG                               $15     !3, 'retry_interval'
         33        SEND_FUNC_ARG                                            $15
         34        DO_FCALL                                      0          
   48    35      > JMP                                                      ->10
         36    >   FE_FREE                                                  $7
   59    37      > RETURN                                                   <true>
   60    38*     > RETURN                                                   null

End of function open

Function read:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kDOjZ
function name:  read
number of ops:  2
compiled vars:  !0 = $sessionId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   64     1      > RETURN                                                   null

End of function read

Function write:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kDOjZ
function name:  write
number of ops:  3
compiled vars:  !0 = $sessionId, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   68     2      > RETURN                                                   null

End of function write

Function parsesavepath:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 141
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 141
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 33
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 47
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
4 jumps found. (Code = 188) Position 1 = 55, Position 2 = 77, Position 3 = 94, Position 4 = 50
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 70
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
2 jumps found. (Code = 43) Position 1 = 106, Position 2 = 138
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 115, Position 2 = 138
Branch analysis from position: 115
2 jumps found. (Code = 77) Position 1 = 116, Position 2 = 137
Branch analysis from position: 116
2 jumps found. (Code = 78) Position 1 = 117, Position 2 = 137
Branch analysis from position: 117
6 jumps found. (Code = 188) Position 1 = 128, Position 2 = 132, Position 3 = 132, Position 4 = 132, Position 5 = 136, Position 6 = 119
Branch analysis from position: 128
1 jumps found. (Code = 42) Position 1 = 136
Branch analysis from position: 136
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
Branch analysis from position: 132
1 jumps found. (Code = 42) Position 1 = 136
Branch analysis from position: 136
Branch analysis from position: 132
Branch analysis from position: 132
Branch analysis from position: 136
Branch analysis from position: 119
2 jumps found. (Code = 44) Position 1 = 121, Position 2 = 128
Branch analysis from position: 121
2 jumps found. (Code = 44) Position 1 = 123, Position 2 = 132
Branch analysis from position: 123
2 jumps found. (Code = 44) Position 1 = 125, Position 2 = 132
Branch analysis from position: 125
2 jumps found. (Code = 44) Position 1 = 127, Position 2 = 132
Branch analysis from position: 127
1 jumps found. (Code = 42) Position 1 = 136
Branch analysis from position: 136
Branch analysis from position: 132
Branch analysis from position: 132
Branch analysis from position: 132
Branch analysis from position: 128
Branch analysis from position: 137
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 137
Branch analysis from position: 138
Branch analysis from position: 138
Branch analysis from position: 70
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 87
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 103
Branch analysis from position: 103
Branch analysis from position: 94
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 55
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 77
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 77
Branch analysis from position: 55
Branch analysis from position: 33
Branch analysis from position: 141
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 141
filename:       /in/kDOjZ
function name:  parseSavePath
number of ops:  144
compiled vars:  !0 = $savePath, !1 = $serverList, !2 = $return, !3 = $url, !4 = $parsedUrlData, !5 = $serverInfo, !6 = $optionList, !7 = $value, !8 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   71     1        ISSET_ISEMPTY_CV                                         !0
          2      > JMPZ                                                     ~9, ->8
   72     3    >   INIT_FCALL                                               'trigger_error'
   73     4        SEND_VAL                                                 'Failed+to+parse+session.save_path+%28empty+save_path%29'
   74     5        SEND_VAL                                                 2
          6        DO_ICALL                                                 
   75     7      > RETURN                                                   <false>
   78     8    >   INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '%2C'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !1, $11
   80    13        ASSIGN                                                   !2, <array>
   81    14      > FE_RESET_R                                       $14     !1, ->141
         15    > > FE_FETCH_R                                               $14, !3, ->141
   82    16    >   INIT_FCALL                                               'strtolower'
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $15     
         19        ASSIGN                                                   !3, $15
   84    20        INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !3
         22        SEND_VAL                                                 0
         23        SEND_VAL                                                 7
         24        DO_ICALL                                         $17     
         25        IS_IDENTICAL                                             $17, 'unix%3A%2F%2F'
         26      > JMPZ                                                     ~18, ->33
   85    27    >   INIT_FCALL                                               'substr'
         28        SEND_VAR                                                 !3
         29        SEND_VAL                                                 7
         30        DO_ICALL                                         $19     
         31        CONCAT                                           ~20     'file%3A%2F%2F', $19
         32        ASSIGN                                                   !3, ~20
   88    33    >   INIT_FCALL                                               'parse_url'
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                         $22     
         36        ASSIGN                                                   !4, $22
   89    37        BOOL_NOT                                         ~24     !4
         38      > JMPZ                                                     ~24, ->47
   90    39    >   INIT_FCALL                                               'trigger_error'
   91    40        CONCAT                                           ~25     'Failed+to+parse+session.save_path+%28unable+to+parse+url%2C+url+was+%27', !3
         41        CONCAT                                           ~26     ~25, '%27%29'
         42        SEND_VAL                                                 ~26
   92    43        SEND_VAL                                                 2
         44        DO_ICALL                                                 
   93    45        FE_FREE                                                  $14
         46      > RETURN                                                   <false>
   97    47    >   ASSIGN                                                   !5, <array>
  104    48        FETCH_DIM_R                                      ~29     !4, 'scheme'
         49      > SWITCH_STRING                                            ~29, [ 'file':->55, 'tcp':->77, ], ->94
         50    >   CASE                                                     ~29, 'file'
         51      > JMPNZ                                                    ~30, ->55
         52    >   CASE                                                     ~29, 'tcp'
         53      > JMPNZ                                                    ~30, ->77
         54    > > JMP                                                      ->94
  106    55    >   INIT_FCALL                                               'substr'
         56        FETCH_DIM_R                                      ~31     !4, 'path'
         57        SEND_VAL                                                 ~31
         58        SEND_VAL                                                 -2
         59        DO_ICALL                                         $32     
         60        IS_IDENTICAL                                             $32, '%3A0'
         61      > JMPZ                                                     ~33, ->70
  107    62    >   INIT_FCALL                                               'substr'
         63        FETCH_DIM_R                                      ~35     !4, 'path'
         64        SEND_VAL                                                 ~35
         65        SEND_VAL                                                 0
         66        SEND_VAL                                                 -2
         67        DO_ICALL                                         $36     
         68        ASSIGN_DIM                                               !4, 'path'
         69        OP_DATA                                                  $36
  109    70    >   FETCH_DIM_R                                      ~38     !4, 'path'
         71        CONCAT                                           ~39     'unix%3A%2F%2F', ~38
         72        ASSIGN_DIM                                               !5, 'host'
         73        OP_DATA                                                  ~39
  110    74        ASSIGN_DIM                                               !5, 'port'
         75        OP_DATA                                                  0
  111    76      > JMP                                                      ->103
  113    77    >   FETCH_DIM_R                                      ~42     !4, 'host'
         78        CONCAT                                           ~43     'tcp%3A%2F%2F', ~42
         79        ASSIGN_DIM                                               !5, 'host'
         80        OP_DATA                                                  ~43
  114    81        ARRAY_KEY_EXISTS                                         'port', !4
         82      > JMPZ                                                     ~44, ->87
  115    83    >   FETCH_DIM_R                                      ~46     !4, 'port'
         84        ASSIGN_DIM                                               !5, 'port'
         85        OP_DATA                                                  ~46
         86      > JMP                                                      ->93
  117    87    >   INIT_FCALL                                               'ini_get'
         88        SEND_VAL                                                 'memcache.default_port'
         89        DO_ICALL                                         $48     
         90        CAST                                          4  ~49     $48
         91        ASSIGN_DIM                                               !5, 'port'
         92        OP_DATA                                                  ~49
  119    93    > > JMP                                                      ->103
  121    94    >   INIT_FCALL                                               'trigger_error'
  122    95        CONCAT                                           ~50     'Failed+to+parse+session.save_path+%28unknown+protocol%2C+url+was+%27', !3
         96        CONCAT                                           ~51     ~50, '%27%29'
         97        SEND_VAL                                                 ~51
  123    98        SEND_VAL                                                 2
         99        DO_ICALL                                                 
  124   100        FREE                                                     ~29
        101        FE_FREE                                                  $14
        102      > RETURN                                                   <false>
        103    >   FREE                                                     ~29
  127   104        ARRAY_KEY_EXISTS                                         'query', !4
        105      > JMPZ                                                     ~53, ->138
  128   106    >   ASSIGN                                                   !6, <array>
  129   107        INIT_FCALL                                               'parse_str'
        108        FETCH_DIM_R                                      ~55     !4, 'query'
        109        SEND_VAL                                                 ~55
        110        SEND_REF                                                 !6
        111        DO_ICALL                                                 
  130   112        COUNT                                            ~57     !6
        113        IS_SMALLER                                               0, ~57
        114      > JMPZ                                                     ~58, ->138
  131   115    > > FE_RESET_R                                       $59     !6, ->137
        116    > > FE_FETCH_R                                       ~60     $59, !7, ->137
        117    >   ASSIGN                                                   !8, ~60
  132   118      > SWITCH_STRING                                            !8, [ 'persistent':->128, 'weight':->132, 'timeout':->132, 'retry_interval':->132, ], ->136
  133   119    >   IS_EQUAL                                                 !8, 'persistent'
        120      > JMPNZ                                                    ~62, ->128
  136   121    >   IS_EQUAL                                                 !8, 'weight'
        122      > JMPNZ                                                    ~62, ->132
  137   123    >   IS_EQUAL                                                 !8, 'timeout'
        124      > JMPNZ                                                    ~62, ->132
  138   125    >   IS_EQUAL                                                 !8, 'retry_interval'
        126      > JMPNZ                                                    ~62, ->132
        127    > > JMP                                                      ->136
  134   128    >   BOOL                                             ~64     !7
        129        ASSIGN_DIM                                               !5, !8
        130        OP_DATA                                                  ~64
  135   131      > JMP                                                      ->136
  139   132    >   CAST                                          4  ~66     !7
        133        ASSIGN_DIM                                               !5, !8
        134        OP_DATA                                                  ~66
  140   135      > JMP                                                      ->136
  131   136    > > JMP                                                      ->116
        137    >   FE_FREE                                                  $59
  146   138    >   ASSIGN_DIM                                               !2
        139        OP_DATA                                                  !5
   81   140      > JMP                                                      ->15
        141    >   FE_FREE                                                  $14
  149   142      > RETURN                                                   !2
  150   143*     > RETURN                                                   null

End of function parsesavepath

End of class MemcacheSessionModule.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.18 ms | 1420 KiB | 29 Q