idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
56,000
public function getParams ( ) { if ( $ this -> cachedParams ) { return $ this -> cachedParams ; } $ CMDS = [ ] ; $ KEYS = [ ] ; $ ARGV = [ ] ; $ KEYNUM = 0 ; $ ARGNUM = 0 ; foreach ( $ this -> stack as $ part ) { list ( $ cmd , $ keys , $ argv ) = $ part ; if ( ! empty ( $ keys ) ) { $ cmd = preg_replace_callback ( '~K...
Return params for eval command
56,001
public function add ( $ cmd , $ keys = null , $ argv = null ) { if ( $ keys !== null ) { if ( is_scalar ( $ keys ) ) { $ keys = [ ( string ) $ keys ] ; } elseif ( ! is_array ( $ keys ) ) { throw new \ Exception ( "Keys must be an array or scalar" ) ; } } if ( $ argv !== null ) { if ( is_scalar ( $ argv ) ) { $ argv = [...
Adds eval command in stack
56,002
public function sighandler ( $ signo ) { if ( ! isset ( self :: $ signals [ $ signo ] ) ) { $ this -> log ( 'caught unknown signal #' . $ signo ) ; return ; } if ( method_exists ( $ this , $ m = strtolower ( self :: $ signals [ $ signo ] ) ) ) { $ this -> $ m ( ) ; } elseif ( method_exists ( $ this , 'sigunknown' ) ) {...
Called when the signal is caught
56,003
public function start ( $ clearstack = true ) { $ pid = \ pcntl_fork ( ) ; if ( $ pid === - 1 ) { throw new \ Exception ( 'Could not fork' ) ; } elseif ( $ pid === 0 ) { $ thread = $ this ; $ thread -> pid = \ posix_getpid ( ) ; if ( ! $ thread -> delayedSigReg ) { $ thread -> registerSignals ( ) ; } if ( $ clearstack ...
Starts the process
56,004
public function sleep ( $ s ) { static $ interval = 0.2 ; $ n = $ s / $ interval ; for ( $ i = 0 ; $ i < $ n ; ++ $ i ) { if ( $ this -> shutdown ) { return false ; } \ usleep ( $ interval * 1000000 ) ; } return true ; }
Delays the process execution for the given number of seconds
56,005
public function stop ( $ kill = false ) { $ this -> shutdown = true ; \ posix_kill ( $ this -> pid , $ kill ? SIGKILL : SIGTERM ) ; }
Terminates the process
56,006
protected function registerEventSignals ( ) { if ( ! EventLoop :: $ instance ) { return ; } foreach ( self :: $ signals as $ no => $ name ) { if ( $ name === 'SIGKILL' || $ name == 'SIGSTOP' ) { continue ; } $ ev = EventLoop :: $ instance -> signal ( $ no , [ $ this , 'eventSighandler' ] , [ $ no ] ) ; if ( ! $ ev ) { ...
Register signals .
56,007
protected function unregisterSignals ( ) { foreach ( $ this -> sigEvents as $ no => $ ev ) { $ ev -> free ( ) ; unset ( $ this -> sigEvents [ $ no ] ) ; } }
Unregister signals .
56,008
protected function waitPid ( ) { start : $ pid = \ pcntl_waitpid ( - 1 , $ status , WNOHANG ) ; if ( $ pid > 0 ) { foreach ( $ this -> collections as $ col ) { foreach ( $ col -> threads as $ k => $ t ) { if ( $ t -> pid === $ pid ) { $ t -> setTerminated ( ) ; unset ( $ col -> threads [ $ k ] ) ; goto start ; } } } } ...
Checks for SIGCHLD
56,009
protected function waitAll ( $ check ) { do { $ n = 0 ; foreach ( $ this -> collections as & $ col ) { $ n += $ col -> removeTerminated ( $ check ) ; } if ( ! $ this -> waitPid ( ) ) { $ this -> sigwait ( 0 , 20000 ) ; } } while ( $ n > 0 ) ; }
Waits until children is alive
56,010
protected function sigwait ( $ sec = 0 , $ nano = 0.3e9 ) { $ siginfo = null ; if ( ! function_exists ( 'pcntl_sigtimedwait' ) ) { $ signo = $ this -> sigtimedwait ( array_keys ( static :: $ signals ) , $ siginfo , $ sec , $ nano ) ; } else { $ signo = @ \ pcntl_sigtimedwait ( array_keys ( static :: $ signals ) , $ sig...
Waits for signals with a timeout
56,011
protected function sigtimedwait ( $ signals , $ siginfo , $ sec , $ nano ) { \ pcntl_signal_dispatch ( ) ; if ( \ time_nanosleep ( $ sec , $ nano ) === true ) { return false ; } \ pcntl_signal_dispatch ( ) ; return true ; }
Implementation of pcntl_sigtimedwait for Mac .
56,012
public function setPeername ( $ host , $ port ) { $ this -> host = $ host ; $ this -> port = $ port ; $ this -> addr = '[' . $ this -> host . ']:' . $ this -> port ; if ( $ this -> pool -> allowedClients !== null ) { if ( ! TCP :: netMatch ( $ this -> pool -> allowedClients , $ this -> host ) ) { Daemon :: log ( 'Conne...
Sets peer name
56,013
public function getSocketName ( & $ addr , & $ port ) { if ( func_num_args ( ) === 0 ) { \ EventUtil :: getSocketName ( $ this -> bev -> fd , $ this -> locAddr , $ this -> locPort ) ; return ; } \ EventUtil :: getSocketName ( $ this -> bev -> fd , $ addr , $ port ) ; }
Get socket name
56,014
public function onFailure ( ) { if ( $ this -> onConnected ) { $ this -> onConnected -> executeAll ( $ this ) ; $ this -> onConnected = null ; } }
Called when the connection failed to be established
56,015
public function onFailureEv ( $ bev = null ) { try { if ( ! $ this -> connected && ! $ this -> failed ) { $ this -> failed = true ; $ this -> onFailure ( ) ; } $ this -> connected = false ; } catch ( \ Exception $ e ) { Daemon :: uncaughtExceptionHandler ( $ e ) ; } }
Called when the connection failed
56,016
protected function initSSLContext ( ) { if ( ! \ EventUtil :: sslRandPoll ( ) ) { Daemon :: $ process -> log ( get_class ( $ this -> pool ) . ': EventUtil::sslRandPoll failed' ) ; return false ; } $ params = [ \ EventSslContext :: OPT_VERIFY_PEER => $ this -> verifypeer , \ EventSslContext :: OPT_ALLOW_SELF_SIGNED => $...
Initialize SSL context
56,017
public function connectUnix ( $ path ) { $ this -> type = 'unix' ; if ( ! $ this -> bevConnectEnabled ) { $ fd = socket_create ( AF_UNIX , SOCK_STREAM , 0 ) ; if ( ! $ fd ) { return false ; } socket_set_nonblock ( $ fd ) ; @ socket_connect ( $ fd , $ path , 0 ) ; $ this -> setFd ( $ fd ) ; return true ; } $ this -> bev...
Establish UNIX socket connection
56,018
public function connectRaw ( $ host ) { $ this -> type = 'raw' ; if ( @ inet_pton ( $ host ) === false ) { \ PHPDaemon \ Clients \ DNS \ Pool :: getInstance ( ) -> resolve ( $ host , function ( $ result ) use ( $ host ) { if ( $ result === false ) { Daemon :: log ( get_class ( $ this ) . '->connectRaw : unable to resol...
Establish raw socket connection
56,019
public function connectUdp ( $ host , $ port ) { $ this -> type = 'udp' ; $ pton = @ inet_pton ( $ host ) ; if ( $ pton === false ) { \ PHPDaemon \ Clients \ DNS \ Pool :: getInstance ( ) -> resolve ( $ host , function ( $ result ) use ( $ host , $ port ) { if ( ! $ result ) { Daemon :: log ( get_class ( $ this ) . '->...
Establish UDP connection
56,020
public function connectTcp ( $ host , $ port ) { $ this -> type = 'tcp' ; $ pton = @ inet_pton ( $ host ) ; $ fd = null ; if ( $ pton === false ) { \ PHPDaemon \ Clients \ DNS \ Pool :: getInstance ( ) -> resolve ( $ this -> host , function ( $ result ) use ( $ host , $ port ) { if ( ! $ result ) { Daemon :: log ( get_...
Establish TCP connection
56,021
public function setOption ( $ level , $ optname , $ val ) { if ( is_resource ( $ this -> fd ) ) { socket_set_option ( $ this -> fd , $ level , $ optname , $ val ) ; } else { \ EventUtil :: setSocketOption ( $ this -> fd , $ level , $ optname , $ val ) ; } }
Set socket option
56,022
protected function onLoad ( ) { if ( isset ( $ this -> minspareworkers -> value ) && $ this -> minspareworkers -> value > 0 && isset ( $ this -> maxspareworkers -> value ) && $ this -> maxspareworkers -> value > 0 ) { if ( $ this -> minspareworkers -> value > $ this -> maxspareworkers -> value ) { Daemon :: log ( '\'mi...
Called when config is loaded
56,023
public function offsetGet ( $ prop ) { $ prop = $ this -> getRealPropertyName ( $ prop ) ; return isset ( $ this -> { $ prop } ) ? $ this -> { $ prop } -> value : null ; }
Get property by name
56,024
public static function loadCmdLineArgs ( $ settings ) { $ error = false ; static $ ktr = [ '-' => '' , ] ; foreach ( $ settings as $ k => $ v ) { $ k = strtolower ( strtr ( $ k , $ ktr ) ) ; if ( $ k === 'config' ) { $ k = 'configfile' ; } if ( ( $ k === 'user' ) || ( $ k === 'group' ) ) { if ( $ v === '' ) { $ v = nul...
Imports parameters from command line args
56,025
public static function prepareEnv ( $ data ) { $ result = [ ] ; $ rows = explode ( "\n" , $ data ) ; for ( $ i = 0 , $ s = sizeof ( $ rows ) ; $ i < $ s ; ++ $ i ) { $ e = self :: extract ( $ rows [ $ i ] ) ; $ result [ $ e [ 0 ] ] = $ e [ 1 ] ; } return $ result ; }
Prepares environment scope
56,026
public static function extract ( $ line ) { $ e = explode ( ': ' , $ line , 2 ) ; $ header = strtolower ( trim ( $ e [ 0 ] ) ) ; $ value = isset ( $ e [ 1 ] ) ? trim ( $ e [ 1 ] ) : null ; $ safe = false ; foreach ( self :: $ safeCaseValues as $ item ) { if ( strncasecmp ( $ header , $ item , mb_orig_strlen ( $ item ) ...
Extract key and value pair from line .
56,027
public static function labels ( $ q ) { $ e = explode ( '.' , $ q ) ; $ r = '' ; for ( $ i = 0 , $ s = sizeof ( $ e ) ; $ i < $ s ; ++ $ i ) { $ r .= chr ( mb_orig_strlen ( $ e [ $ i ] ) ) . $ e [ $ i ] ; } if ( mb_orig_substr ( $ r , - 1 ) !== "\x00" ) { $ r .= "\x00" ; } return $ r ; }
Build structure of labels
56,028
public static function parseLabels ( & $ data , $ orig = null ) { $ str = '' ; while ( mb_orig_strlen ( $ data ) > 0 ) { $ l = ord ( $ data [ 0 ] ) ; if ( $ l >= 192 ) { $ pos = Binary :: bytes2int ( chr ( $ l - 192 ) . mb_orig_substr ( $ data , 1 , 1 ) ) ; $ data = mb_orig_substr ( $ data , 2 ) ; $ ref = mb_orig_subst...
Parse structure of labels
56,029
public static function bytes2int ( $ str , $ l = false ) { if ( $ l ) { $ str = strrev ( $ str ) ; } $ dec = 0 ; $ len = mb_orig_strlen ( $ str ) ; for ( $ i = 0 ; $ i < $ len ; ++ $ i ) { $ dec += ord ( mb_orig_substr ( $ str , $ i , 1 ) ) * pow ( 0x100 , $ len - $ i - 1 ) ; } return $ dec ; }
Convert bytes into integer
56,030
public static function getByte ( & $ p ) { $ r = static :: bytes2int ( $ p { 0 } ) ; $ p = mb_orig_substr ( $ p , 1 ) ; return ( int ) $ r ; }
Parse byte and remove it
56,031
public static function getString ( & $ str ) { $ p = mb_orig_strpos ( $ str , "\x00" ) ; if ( $ p === false ) { return '' ; } $ r = mb_orig_substr ( $ str , 0 , $ p ) ; $ str = mb_orig_substr ( $ str , $ p + 1 ) ; return $ r ; }
Parse nul - terminated string
56,032
public static function getLV ( & $ p , $ l = 1 , $ nul = false , $ lrev = false ) { $ s = static :: b2i ( mb_orig_substr ( $ p , 0 , $ l ) , ! ! $ lrev ) ; $ p = mb_orig_substr ( $ p , $ l ) ; if ( $ s === 0 ) { return '' ; } $ r = '' ; if ( mb_orig_strlen ( $ p ) < $ s ) { Daemon :: log ( 'getLV error: buf length (' ....
Parse length - value structure
56,033
public static function flags2bitarray ( $ flags , $ len = 4 ) { $ ret = 0 ; foreach ( $ flags as $ v ) { $ ret |= $ v ; } return static :: i2b ( $ len , $ ret ) ; }
Convert array of flags into bit array
56,034
public static function bitmap2bytes ( $ bitmap , $ check_len = 0 ) { $ r = '' ; $ bitmap = str_pad ( $ bitmap , ceil ( mb_orig_strlen ( $ bitmap ) / 8 ) * 8 , '0' , STR_PAD_LEFT ) ; for ( $ i = 0 , $ n = mb_orig_strlen ( $ bitmap ) / 8 ; $ i < $ n ; ++ $ i ) { $ r .= chr ( ( int ) bindec ( mb_orig_substr ( $ bitmap , $...
Convert bitmap into bytes
56,035
public function initSlave ( $ point ) { $ this -> db -> { 'local.oplog.$main' } -> find ( function ( $ cursor ) { $ this -> cursor = $ cursor ; $ cursor -> state = 1 ; $ cursor -> lastOpId = null ; foreach ( $ cursor -> items as $ k => & $ item ) { if ( \ PHPDaemon \ Core \ Daemon :: $ config -> logevents -> value ) { ...
Initializes slave session .
56,036
public function cacheObject ( $ o ) { if ( \ PHPDaemon \ Core \ Daemon :: $ config -> logevents -> value ) { \ PHPDaemon \ Core \ Daemon :: log ( __METHOD__ . '(' . json_encode ( $ o ) . ')' ) ; } if ( isset ( $ o [ '_key' ] ) ) { $ this -> cache -> set ( $ o [ '_key' ] , bson_encode ( $ o ) ) ; $ this -> cache -> set ...
Method called when object received .
56,037
public function deleteObject ( $ o ) { if ( \ PHPDaemon \ Core \ Daemon :: $ config -> logevents -> value ) { \ PHPDaemon \ Core \ Daemon :: log ( __METHOD__ . '(' . json_encode ( $ o ) . ')' ) ; } $ this -> cache -> get ( '_id.' . ( ( string ) $ o [ '_id' ] ) , function ( $ mc ) use ( $ o ) { if ( is_string ( $ m -> r...
Method called when object deleted .
56,038
public function push ( Generic $ thread ) { $ id = ++ $ this -> spawnCounter ; $ thread -> setId ( $ id ) ; $ this -> threads [ $ id ] = $ thread ; }
Pushes certain thread to the collection
56,039
public function stop ( $ kill = false ) { foreach ( $ this -> threads as $ thread ) { $ thread -> stop ( $ kill ) ; } }
Stop all collected threads
56,040
public function removeTerminated ( ) { $ n = 0 ; foreach ( $ this -> threads as $ id => $ thread ) { if ( ! $ thread -> getPid ( ) || ! $ thread -> ifExists ( ) ) { $ thread -> setTerminated ( ) ; unset ( $ this -> threads [ $ id ] ) ; continue ; } ++ $ n ; } return $ n ; }
Remove terminated threads from the collection
56,041
public static function init ( ) { if ( ! Daemon :: $ config -> eioenabled -> value ) { self :: $ supported = false ; return ; } if ( ! self :: $ supported = Daemon :: loadModuleIfAbsent ( 'eio' , self :: $ eioVer ) ) { Daemon :: log ( 'FS: missing pecl-eio >= ' . self :: $ eioVer . '. Filesystem I/O performance comprom...
Initialize FS driver
56,042
public static function initEvent ( ) { if ( ! self :: $ supported ) { return ; } self :: updateConfig ( ) ; self :: $ fd = eio_get_event_stream ( ) ; self :: $ ev = EventLoop :: $ instance -> event ( self :: $ fd , \ Event :: READ | \ Event :: PERSIST , function ( $ fd , $ events , $ arg ) { while ( eio_nreqs ( ) ) { e...
Initialize main FS event
56,043
public static function updateConfig ( ) { if ( Daemon :: $ config -> eiosetmaxidle -> value !== null ) { eio_set_max_idle ( Daemon :: $ config -> eiosetmaxidle -> value ) ; } if ( Daemon :: $ config -> eiosetmaxparallel -> value !== null ) { eio_set_max_parallel ( Daemon :: $ config -> eiosetmaxparallel -> value ) ; } ...
Called when config is updated
56,044
public static function rmdir ( $ path , $ cb = null , $ pri = EIO_PRI_DEFAULT ) { $ cb = CallbackWrapper :: forceWrap ( $ cb ) ; if ( ! FileSystem :: $ supported ) { $ r = rmdir ( $ path ) ; if ( $ cb ) { $ cb ( $ path , $ r ) ; } return $ r ; } return eio_rmdir ( $ path , $ pri , $ cb , $ path ) ; }
Removes empty directory
56,045
public static function genRndTempnam ( $ dir = null , $ prefix = 'php' ) { if ( ! $ dir ) { $ dir = sys_get_temp_dir ( ) ; } static $ n = 0 ; return $ dir . '/' . $ prefix . str_shuffle ( md5 ( str_shuffle ( microtime ( true ) . chr ( mt_rand ( 0 , 0xFF ) ) . Daemon :: $ process -> getPid ( ) . chr ( mt_rand ( 0 , 0xFF...
Returns random temporary file name
56,046
protected static function tempnamHandler ( $ dir , $ prefix , $ cb , & $ tries ) { $ cb = CallbackWrapper :: forceWrap ( $ cb ) ; if ( ++ $ tries >= 3 ) { $ cb ( false ) ; return ; } $ path = FileSystem :: genRndTempnam ( $ dir , $ prefix ) ; FileSystem :: open ( $ path , 'x+!' , function ( $ file ) use ( $ dir , $ pre...
Generates closure tempnam handler
56,047
public static function tempnam ( $ dir , $ prefix , $ cb ) { $ cb = CallbackWrapper :: forceWrap ( $ cb ) ; if ( ! FileSystem :: $ supported ) { FileSystem :: open ( tempnam ( $ dir , $ prefix ) , 'w!' , $ cb ) ; } $ tries = 0 ; static :: tempnamHandler ( $ dir , $ prefix , $ cb , $ tries ) ; }
Obtain exclusive temporary file
56,048
public static function forceWrap ( $ cb , $ timeout = null ) { if ( $ cb instanceof CallbackWrapper ) { return $ cb ; } if ( $ cb === null ) { return null ; } return new static ( $ cb , $ timeout , Daemon :: $ context ) ; }
Wraps callback even without context
56,049
public function getRequest ( $ req , $ upstream , $ responder = null ) { if ( isset ( $ req -> attrs -> server [ 'APPNAME' ] ) ) { $ appName = $ req -> attrs -> server [ 'APPNAME' ] ; } elseif ( $ responder !== null ) { $ appName = $ responder ; } elseif ( ( $ appName = $ this -> getRequestRoute ( $ req , $ upstream ) ...
Routes incoming request to related application
56,050
public function setHumanValue ( $ value ) { $ this -> humanValue = $ value ; $ old = $ this -> value ; $ this -> value = static :: humanToPlain ( $ value ) ; $ this -> onUpdate ( $ old ) ; }
Set human - readable value
56,051
public function pushValue ( $ value ) { $ old = $ this -> value ; if ( ! $ this -> stackable ) { $ this -> setValue ( $ value ) ; return ; } if ( ! is_array ( $ this -> value ) ) { $ this -> value = [ $ this -> value , $ value ] ; } else { $ f = false ; foreach ( $ this -> value as $ k => $ v ) { if ( ! is_int ( $ k ) ...
Push plain value
56,052
private function parseTable ( ) { $ length = $ this -> parseUnsignedInt32 ( ) ; $ stopAt = strlen ( $ this -> buffer ) - $ length ; $ table = [ ] ; while ( strlen ( $ this -> buffer ) > $ stopAt ) { $ table [ $ this -> parseShortString ( ) ] = $ this -> parseField ( ) ; } return $ table ; }
Parse an AMQP table from the head of the buffer .
56,053
private function parseField ( ) { $ type = $ this -> buffer [ 0 ] ; $ this -> buffer = substr ( $ this -> buffer , 1 ) ; switch ( $ type ) { case 's' : return $ this -> parseSignedInt16 ( ) ; case 'l' : return $ this -> parseSignedInt64 ( ) ; case 'x' : return $ this -> parseByteArray ( ) ; case 't' : return $ this -> ...
Parse a table or array field .
56,054
public function parseDecimal ( ) { $ scale = $ this -> parseUnsignedInt8 ( ) ; $ value = $ this -> parseSignedInt32 ( ) ; if ( 0 === $ scale ) { return ( string ) $ value ; } if ( $ value >= 0 ) { $ sign = '' ; $ value = ( string ) $ value ; } else { $ sign = '-' ; $ value = ( string ) - $ value ; } $ length = strlen (...
Parse an AMQP decimal from the head of the buffer .
56,055
private function parseArray ( ) { $ length = $ this -> parseUnsignedInt32 ( ) ; $ stopAt = strlen ( $ this -> buffer ) - $ length ; $ array = [ ] ; while ( strlen ( $ this -> buffer ) > $ stopAt ) { $ array [ ] = $ this -> parseField ( ) ; } return $ array ; }
Parse an AMQP field - array value .
56,056
private function parseByteArray ( ) { list ( , $ length ) = unpack ( 'N' , $ this -> buffer ) ; try { return substr ( $ this -> buffer , 4 , $ length ) ; } finally { $ this -> buffer = substr ( $ this -> buffer , $ length + 4 ) ; } }
Parse an AMQP byte - array value .
56,057
public function onResponse ( $ cb ) { if ( $ cb === null && ! $ this -> noSAF ) { return ; } $ this -> onResponse -> push ( $ cb ) ; $ this -> checkFree ( ) ; }
Push callback to onReponse stack
56,058
public function fileNotFound ( ) { try { $ this -> header ( '404 Not Found' ) ; $ this -> header ( 'Content-Type: text/html' ) ; } catch ( \ PHPDaemon \ Request \ RequestHeadersAlreadySent $ e ) { } $ this -> out ( 'File not found.' ) ; }
Send header 404 or if not possible already response File not found
56,059
public function sendEcho ( $ cb , $ data = 'phpdaemon' ) { ++ $ this -> seq ; if ( mb_orig_strlen ( $ data ) % 2 !== 0 ) { $ data .= "\x00" ; } $ packet = pack ( 'ccnnn' , 8 , 0 , 0 , Daemon :: $ process -> getPid ( ) , $ this -> seq ) . $ data ; $ packet = substr_replace ( $ packet , self :: checksum ( $ packet ) , 2 ...
Send echo - request
56,060
public static function ensureCallback ( & $ arg ) { if ( $ arg instanceof \ Closure ) { return true ; } if ( is_array ( $ arg ) && sizeof ( $ arg ) === 2 ) { if ( isset ( $ arg [ 0 ] ) && $ arg [ 0 ] instanceof \ PHPDaemon \ WebSocket \ Route ) { if ( isset ( $ arg [ 1 ] ) && is_string ( $ arg [ 1 ] ) && strncmp ( $ ar...
Ensures that the variable passed by reference holds a valid callback - function If it doesn t its value will be reset to null
56,061
protected function defineLocalMethods ( $ arr = [ ] ) { foreach ( get_class_methods ( $ this ) as $ m ) { if ( substr ( $ m , - 6 ) === 'Method' ) { $ k = substr ( $ m , 0 , - 6 ) ; if ( $ k === 'methods' ) { continue ; } $ arr [ $ k ] = [ $ this , $ m ] ; } } foreach ( $ arr as $ k => $ v ) { $ this -> localMethods [ ...
Defines local methods
56,062
public static function exportObjectMethods ( $ object ) { $ methods = [ ] ; foreach ( get_class_methods ( $ object ) as $ method ) { if ( $ method [ 0 ] === '_' ) { continue ; } $ methods [ $ method ] = [ $ object , $ method ] ; } return $ methods ; }
Export object methods
56,063
public function callRemoteArray ( $ method , $ args ) { if ( isset ( $ this -> remoteMethods [ $ method ] ) ) { $ this -> remoteMethods [ $ method ] ( ... $ args ) ; return $ this ; } $ pct = [ 'method' => $ method , ] ; if ( sizeof ( $ args ) ) { $ callbacks = [ ] ; $ path = [ ] ; $ this -> extractCallbacks ( $ args ,...
Calls a remote method with array of arguments
56,064
protected function extractCallbacks ( & $ args , & $ list , & $ path ) { foreach ( $ args as $ k => & $ v ) { if ( is_array ( $ v ) ) { if ( sizeof ( $ v ) === 2 ) { if ( isset ( $ v [ 0 ] ) && is_object ( $ v [ 0 ] ) ) { if ( isset ( $ v [ 1 ] ) && is_string ( $ v [ 1 ] ) ) { $ id = ++ $ this -> counter ; if ( $ this ...
Extracts callback functions from array of arguments
56,065
public function callLocal ( ... $ args ) { if ( ! sizeof ( $ args ) ) { return $ this ; } $ method = array_shift ( $ args ) ; $ p = [ 'method' => $ method , 'arguments' => $ args , ] ; $ this -> onPacket ( $ p ) ; return $ this ; }
Calls a local method
56,066
public function onPacket ( $ pct ) { if ( $ this -> cleaned ) { return ; } $ m = isset ( $ pct [ 'method' ] ) ? $ pct [ 'method' ] : null ; $ args = isset ( $ pct [ 'arguments' ] ) ? $ pct [ 'arguments' ] : [ ] ; if ( isset ( $ pct [ 'callbacks' ] ) && is_array ( $ pct [ 'callbacks' ] ) ) { foreach ( $ pct [ 'callbacks...
Called when new packet is received
56,067
protected static function setPath ( & $ m , $ path , $ val ) { foreach ( $ path as $ p ) { $ m = & $ m [ $ p ] ; } $ m = $ val ; }
Sets value by materialized path
56,068
protected static function & getPath ( & $ m , $ path ) { foreach ( $ path as $ p ) { $ m = & $ m [ $ p ] ; } return $ m ; }
Finds value by materialized path
56,069
public function cleanup ( ) { $ this -> cleaned = true ; $ this -> remoteMethods = [ ] ; $ this -> localMethods = [ ] ; $ this -> persistentCallbacks = [ ] ; $ this -> callbacks = [ ] ; }
Swipes internal structures
56,070
public function onFrame ( $ data , $ type ) { foreach ( explode ( "\n" , $ data ) as $ pct ) { if ( $ pct === '' ) { continue ; } $ this -> onPacket ( json_decode ( $ pct , true ) ) ; } }
Called when new frame is received
56,071
public function bind ( $ event , $ cb ) { if ( $ cb !== null ) { $ cb = CallbackWrapper :: wrap ( $ cb ) ; } $ event = ( array ) $ event ; foreach ( $ event as $ e ) { CallbackWrapper :: addToArray ( $ this -> eventHandlers [ $ e ] , $ cb ) ; } return $ this ; }
Bind event or events
56,072
public function each ( $ method , ... $ args ) { if ( $ this -> count ( ) === 0 ) { return 0 ; } $ n = 0 ; foreach ( $ this as $ obj ) { $ obj -> $ method ( ... $ args ) ; ++ $ n ; } return $ n ; }
Call given method of all objects in storage
56,073
public function removeAll ( $ obj = null ) { if ( $ obj === null ) { $ this -> removeAllExcept ( new \ SplObjectStorage ) ; } parent :: removeAll ( $ obj ) ; }
Remove all objects from this storage which contained in another storage
56,074
public function detachFirst ( ) { $ this -> rewind ( ) ; $ o = $ this -> current ( ) ; if ( ! $ o ) { return false ; } $ this -> detach ( $ o ) ; return $ o ; }
Detaches first object and returns it
56,075
public function ping ( $ addr , $ cb ) { $ e = explode ( ':' , $ addr ) ; $ this -> getConnection ( 'valve://[udp:' . $ e [ 0 ] . ']' . ( isset ( $ e [ 1 ] ) ? ':' . $ e [ 1 ] : '' ) . '/ping' , function ( $ conn ) use ( $ cb ) { if ( ! $ conn -> connected ) { $ cb ( $ conn , false ) ; return ; } $ mt = microtime ( tru...
Sends echo - request
56,076
public function finish ( ) { $ this -> xml_depth = 0 ; $ this -> current_ns = [ ] ; $ this -> idhandlers = [ ] ; $ this -> xpathhandlers = [ ] ; $ this -> eventHandlers = [ ] ; }
Finishes the stream
56,077
public function addXPathHandler ( $ xpath , $ cb , $ obj = null ) { if ( preg_match_all ( "/\(?{[^\}]+}\)?(\/?)[^\/]+/" , $ xpath , $ regs ) ) { $ ns_tags = $ regs [ 0 ] ; } else { $ ns_tags = [ $ xpath ] ; } foreach ( $ ns_tags as $ ns_tag ) { list ( $ l , $ r ) = explode ( "}" , $ ns_tag ) ; if ( $ r !== null ) { $ x...
Add XPath Handler
56,078
public function sendTo ( $ data , $ flags , $ host , $ port ) { return socket_sendto ( $ this -> fd , $ data , mb_orig_strlen ( $ data ) , $ flags , $ host , $ port ) ; }
Send UDP packet
56,079
public function bindSocket ( ) { $ sock = socket_create ( AF_INET , SOCK_DGRAM , SOL_UDP ) ; if ( ! $ sock ) { $ errno = socket_last_error ( ) ; Daemon :: $ process -> log ( get_class ( $ this ) . ': Couldn\'t create UDP-socket (' . $ errno . ' - ' . socket_strerror ( $ errno ) . ').' ) ; return false ; } if ( ! isset ...
Bind given addreess
56,080
public function onReadUdp ( $ stream = null , $ events = 0 , $ arg = null ) { if ( Daemon :: $ process -> reload ) { return false ; } if ( $ this -> pool -> maxConcurrency ) { if ( $ this -> pool -> count ( ) >= $ this -> pool -> maxConcurrency ) { $ this -> overload = true ; return false ; } } $ host = null ; do { $ l...
Called when we got UDP packet
56,081
public function closeWrite ( ) { if ( $ this -> bevWrite ) { if ( isset ( $ this -> bevWrite ) ) { $ this -> bevWrite -> free ( ) ; } $ this -> bevWrite = null ; } if ( $ this -> fdWrite ) { fclose ( $ this -> fdWrite ) ; $ this -> fdWrite = null ; } return $ this ; }
Close write stream
56,082
public function close ( ) { parent :: close ( ) ; $ this -> closeWrite ( ) ; if ( is_resource ( $ this -> pd ) ) { proc_close ( $ this -> pd ) ; } }
Close the process
56,083
public function writeln ( $ data ) { if ( ! $ this -> alive ) { Daemon :: log ( 'Attempt to write to dead IOStream (' . get_class ( $ this ) . ')' ) ; return false ; } if ( ! isset ( $ this -> bevWrite ) ) { return false ; } if ( ! mb_orig_strlen ( $ data ) && ! mb_orig_strlen ( $ this -> EOL ) ) { return true ; } $ th...
Send data and appending \ n to connection . Note that it just writes to buffer flushed at every baseloop
56,084
public function readLine ( $ eol = null ) { if ( ! isset ( $ this -> bev ) ) { return null ; } return $ this -> bev -> input -> readLine ( $ eol ? : $ this -> EOLS ) ; }
Reads line from buffer
56,085
public function drainIfMatch ( $ str ) { if ( ! isset ( $ this -> bev ) ) { return false ; } $ in = $ this -> bev -> input ; $ l = mb_orig_strlen ( $ str ) ; $ ll = $ in -> length ; if ( $ ll === 0 ) { return $ l === 0 ? true : null ; } if ( $ ll < $ l ) { return $ in -> search ( substr ( $ str , 0 , $ ll ) ) === 0 ? n...
Drains buffer it matches the string
56,086
public function prependInput ( $ str ) { if ( ! isset ( $ this -> bev ) ) { return false ; } return $ this -> bev -> input -> prepend ( $ str ) ; }
Prepends data to input buffer
56,087
public function prependOutput ( $ str ) { if ( ! isset ( $ this -> bev ) ) { return false ; } return $ this -> bev -> output -> prepend ( $ str ) ; }
Prepends data to output buffer
56,088
public function search ( $ what , $ start = 0 , $ end = - 1 ) { return $ this -> bev -> input -> search ( $ what , $ start , $ end ) ; }
Searches first occurence of the string in input buffer
56,089
public function finish ( ) { if ( $ this -> finished ) { return ; } $ this -> finished = true ; $ this -> eventLoop -> interrupt ( ) ; $ this -> onFinish ( ) ; if ( ! $ this -> writing ) { $ this -> close ( ) ; } }
Finish the session . You should not worry about buffers they are going to be flushed properly
56,090
public function onReadEv ( $ bev ) { if ( ! $ this -> ready ) { $ this -> wRead = true ; return ; } if ( $ this -> finished ) { return ; } try { $ this -> onRead ( ) ; } catch ( \ Exception $ e ) { Daemon :: uncaughtExceptionHandler ( $ e ) ; } }
Called when the connection has got new data
56,091
public function onWriteOnce ( $ cb ) { if ( ! $ this -> writing ) { $ cb ( $ this ) ; return ; } $ this -> onWriteOnce -> push ( $ cb ) ; }
Push callback which will be called only once when writing is available next time
56,092
public function onWriteEv ( $ bev ) { $ this -> writing = false ; if ( $ this -> finished ) { if ( $ this -> bev -> output -> length === 0 ) { $ this -> close ( ) ; } return ; } if ( ! $ this -> ready ) { $ this -> ready = true ; while ( ! $ this -> onWriteOnce -> isEmpty ( ) ) { try { $ this -> onWriteOnce -> executeO...
Called when the connection is ready to accept new data
56,093
public function onStateEv ( $ bev , $ events ) { if ( $ events & \ EventBufferEvent :: CONNECTED ) { $ this -> onWriteEv ( $ bev ) ; } elseif ( $ events & \ EventBufferEvent :: TIMEOUT ) { $ this -> timedout = true ; $ this -> finish ( ) ; } elseif ( $ events & ( \ EventBufferEvent :: ERROR | \ EventBufferEvent :: EOF ...
Called when the connection state changed
56,094
public function moveToBuffer ( \ EventBuffer $ dest , $ n ) { if ( ! isset ( $ this -> bev ) ) { return false ; } return $ dest -> appendFrom ( $ this -> bev -> input , $ n ) ; }
Moves arbitrary number of bytes from input buffer to given buffer
56,095
public function writeFromBuffer ( \ EventBuffer $ src , $ n ) { if ( ! isset ( $ this -> bev ) ) { return false ; } $ this -> writing = true ; return $ this -> bev -> output -> appendFrom ( $ src , $ n ) ; }
Moves arbitrary number of bytes from given buffer to output buffer
56,096
public function read ( $ n ) { if ( $ n <= 0 ) { return '' ; } if ( ! isset ( $ this -> bev ) ) { return false ; } $ read = $ this -> bev -> read ( $ n ) ; if ( $ read === null ) { return false ; } return $ read ; }
Read data from the connection s buffer
56,097
public function readUnlimited ( ) { if ( ! isset ( $ this -> bev ) ) { return false ; } $ read = $ this -> bev -> read ( $ this -> bev -> input -> length ) ; if ( $ read === null ) { return false ; } return $ read ; }
Reads all data from the connection s buffer
56,098
public function eventCall ( $ arg ) { try { if ( $ this -> state === Generic :: STATE_FINISHED ) { $ this -> finish ( ) ; $ this -> free ( ) ; return ; } $ this -> state = Generic :: STATE_RUNNING ; $ this -> onWakeup ( ) ; $ throw = false ; try { $ ret = $ this -> run ( ) ; if ( ( $ ret === Generic :: STATE_FINISHED )...
Event handler of Request called by Evtimer
56,099
public function free ( ) { if ( $ this -> ev ) { $ this -> ev -> free ( ) ; $ this -> ev = null ; } if ( isset ( $ this -> upstream ) ) { $ this -> upstream -> freeRequest ( $ this ) ; $ this -> upstream = null ; } }
Frees the request