idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
56,100 | public function setPriority ( $ p ) { $ this -> priority = $ p ; if ( $ this -> ev !== null ) { $ this -> ev -> priority = $ p ; } } | Sets the priority |
56,101 | public static function getString ( & $ var , $ values = null ) { if ( ! is_string ( $ var ) ) { $ var = '' ; } if ( $ values !== null ) { return in_array ( $ var , $ values , true ) ? $ var : $ values [ 0 ] ; } return $ var ; } | Get string value from the given variable |
56,102 | public static function getInteger ( & $ var , $ values = null ) { if ( is_string ( $ var ) && ctype_digit ( $ var ) ) { $ var = ( int ) $ var ; } if ( ! is_int ( $ var ) ) { return 0 ; } if ( $ values !== null ) { return in_array ( $ var , $ values , true ) ? $ var : $ values [ 0 ] ; } return $ var ; } | Get integer value from the given variable |
56,103 | public function unregisterShutdownFunction ( $ callback ) { if ( ( $ k = array_search ( $ callback , $ this -> shutdownFuncs ) ) !== false ) { unset ( $ this -> shutdownFuncs [ $ k ] ) ; } } | Remove the given callback |
56,104 | public function codepoint ( $ p ) { if ( $ this -> codepoint !== $ p ) { $ this -> codepoint = $ p ; return true ; } return false ; } | Helper for easy switching between several interruptable stages of request s execution |
56,105 | public function sleep ( $ time = 0 , $ set = false ) { if ( $ this -> state === Generic :: STATE_FINISHED ) { return ; } if ( $ this -> state !== Generic :: STATE_RUNNING ) { $ set = true ; } $ this -> sleepTime = $ time ; if ( ! $ set ) { throw new RequestSleep ; } else { $ this -> ev -> del ( ) ; $ this -> ev -> add ... | Delays the request execution for the given number of seconds |
56,106 | public function wakeup ( ) { if ( $ this -> state === Generic :: STATE_WAITING ) { $ this -> ev -> del ( ) ; $ this -> ev -> add ( 0 ) ; } } | Cancel current sleep |
56,107 | public function abort ( ) { if ( $ this -> aborted ) { return ; } $ this -> aborted = true ; $ this -> onWakeup ( ) ; $ this -> onAbort ( ) ; if ( ( ignore_user_abort ( ) === 1 ) && ( ( $ this -> state === Generic :: STATE_RUNNING ) || ( $ this -> state === Generic :: STATE_WAITING ) ) && ! Daemon :: $ compatMode ) { $... | Aborts the request |
56,108 | public function finish ( $ status = 0 , $ zombie = false ) { if ( $ this -> state === Generic :: STATE_FINISHED ) { return ; } if ( ! $ zombie ) { $ this -> state = Generic :: STATE_FINISHED ; } if ( ! ( $ r = $ this -> running ) ) { $ this -> onWakeup ( ) ; } while ( ( $ cb = array_shift ( $ this -> shutdownFuncs ) ) ... | Finish the request |
56,109 | public function printObj ( $ depth = 0 ) { $ s = str_repeat ( "\t" , $ depth ) . $ this -> name . " " . $ this -> ns . ' ' . $ this -> data . "\n" ; foreach ( $ this -> subs as $ sub ) { $ s .= $ sub -> printObj ( $ depth + 1 ) ; } return $ s ; } | Dump this XML Object to output . |
56,110 | public function toString ( $ str = '' ) { $ str .= "<{$this->name} xmlns='{$this->ns}' " ; foreach ( $ this -> attrs as $ key => $ value ) { if ( $ key !== 'xmlns' ) { $ value = htmlspecialchars ( $ value ) ; $ str .= "$key='$value' " ; } } $ str .= ">" ; foreach ( $ this -> subs as $ sub ) { $ str .= $ sub -> toString... | Return this XML Object in xml notation |
56,111 | public function hasSub ( $ name , $ ns = null ) { foreach ( $ this -> subs as $ sub ) { if ( ( $ name === "*" or $ sub -> name === $ name ) and ( $ ns === null or $ sub -> ns === $ ns ) ) { return true ; } } return false ; } | Has this XML Object the given sub? |
56,112 | public function sub ( $ name , $ attrs = null , $ ns = null ) { foreach ( $ this -> subs as $ sub ) { if ( $ sub -> name === $ name and ( $ ns === null or $ sub -> ns === $ ns ) ) { return $ sub ; } } return null ; } | Return a sub |
56,113 | public static function exportBytes ( $ str , $ all = false ) { return preg_replace_callback ( '~' . ( $ all ? '.' : '[^A-Za-z\d\.\{\}$<>:;\-_/\\\\=+]' ) . '~s' , function ( $ m ) use ( $ all ) { if ( ! $ all ) { if ( $ m [ 0 ] === "\r" ) { return "\n" . '\r' ; } if ( $ m [ 0 ] === "\n" ) { return '\n' ; } } return spri... | Export binary data |
56,114 | public static function proxy ( $ cb , $ name = null ) { static $ i = 0 ; $ n = ++ $ i ; Daemon :: log ( 'Debug::proxy #' . $ n . ': SPAWNED (' . json_encode ( $ name ) . ')' ) ; return function ( ... $ args ) use ( $ cb , $ name , $ n ) { Daemon :: log ( 'Debug::proxy #' . $ n . ': CALLED (' . json_encode ( $ name ) . ... | Returns a proxy callback function with logging for debugging purposes |
56,115 | public static function dump ( ... $ args ) { ob_start ( ) ; foreach ( $ args as $ v ) { var_dump ( $ v ) ; } $ dump = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ dump ; } | Wrapper of var_dump |
56,116 | public static function zdump ( ... $ args ) { ob_start ( ) ; foreach ( $ args as $ v ) { debug_zval_dump ( $ v ) ; } $ dump = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ dump ; } | Wrapper of debug_zval_dump |
56,117 | public static function backtrace ( $ bool = false ) { if ( Daemon :: $ obInStack || $ bool ) { try { throw new \ Exception ; } catch ( \ Exception $ e ) { $ trace = $ e -> getTraceAsString ( ) ; $ e = explode ( "\n" , $ trace ) ; array_shift ( $ e ) ; array_shift ( $ e ) ; return implode ( "\n" , $ e ) ; } } ob_start (... | Returns textual backtrace |
56,118 | public function requestPlayers ( $ cb ) { $ this -> request ( 'challenge' , null , function ( $ conn , $ result ) use ( $ cb ) { if ( is_array ( $ result ) ) { $ cb ( $ conn , $ result ) ; return ; } $ conn -> request ( 'players' , $ result , $ cb ) ; } ) ; } | Sends a request of type players |
56,119 | public static function parsePlayers ( & $ st ) { $ playersn = Binary :: getByte ( $ st ) ; $ players = [ ] ; for ( $ i = 1 ; $ i < $ playersn ; ++ $ i ) { $ n = Binary :: getByte ( $ st ) ; $ name = Binary :: getString ( $ st ) ; $ score = Binary :: getDWord ( $ st , true ) ; if ( mb_orig_strlen ( $ st ) === 0 ) { brea... | Parses response to players command into structure |
56,120 | public function getConnection ( $ url = null , $ cb = null , $ pri = 0 ) { if ( ! is_string ( $ url ) && $ url !== null && $ cb === null ) { $ cb = $ url ; $ url = null ; } if ( $ url === null ) { if ( isset ( $ this -> config -> server -> value ) ) { $ url = $ this -> config -> server -> value ; } elseif ( isset ( $ t... | Returns available connection from the pool |
56,121 | public function markConnFree ( ClientConnection $ conn , $ url ) { if ( ! isset ( $ this -> servConnFree [ $ url ] ) ) { return ; } $ this -> servConnFree [ $ url ] -> attach ( $ conn ) ; } | Mark connection as free |
56,122 | public function markConnBusy ( ClientConnection $ conn , $ url ) { if ( ! isset ( $ this -> servConnFree [ $ url ] ) ) { return ; } $ this -> servConnFree [ $ url ] -> detach ( $ conn ) ; } | Mark connection as busy |
56,123 | public function detachConnFromUrl ( ClientConnection $ conn , $ url ) { if ( isset ( $ this -> servConnFree [ $ url ] ) ) { $ this -> servConnFree [ $ url ] -> detach ( $ conn ) ; } if ( isset ( $ this -> servConn [ $ url ] ) ) { $ this -> servConn [ $ url ] -> detach ( $ conn ) ; } } | Detaches connection from URL |
56,124 | public function touchPending ( $ url ) { while ( isset ( $ this -> pending [ $ url ] ) && ! $ this -> pending [ $ url ] -> isEmpty ( ) ) { if ( true === $ this -> getConnection ( $ url , $ this -> pending [ $ url ] -> dequeue ( ) ) ) { return ; } } } | Touch pending requests for connection |
56,125 | public function getConnectionByKey ( $ key , $ cb = null ) { if ( is_object ( $ key ) ) { return $ key -> onConnected ( $ cb ) ; } srand ( crc32 ( $ key ) ) ; $ addr = array_rand ( $ this -> servers ) ; srand ( ) ; return $ this -> getConnection ( $ addr , $ cb ) ; } | Returns available connection from the pool by key |
56,126 | public function requestByServer ( $ server , $ data , $ onResponse = null ) { $ this -> getConnection ( $ server , function ( $ conn ) use ( $ data , $ onResponse ) { if ( ! $ conn -> isConnected ( ) ) { return ; } $ conn -> onResponse ( $ onResponse ) ; $ conn -> write ( $ data ) ; } ) ; return true ; } | Sends a request to arbitrary server |
56,127 | public function requestByKey ( $ key , $ data , $ onResponse = null ) { $ this -> getConnectionByKey ( $ key , function ( $ conn ) use ( $ data , $ onResponse ) { if ( ! $ conn -> isConnected ( ) ) { return ; } $ conn -> onResponse ( $ onResponse ) ; $ conn -> write ( $ data ) ; } ) ; return true ; } | Sends a request to server according to the key |
56,128 | public function stdin ( $ c ) { if ( $ c === '' ) { $ this -> onWrite ( $ this -> proc ) ; } else { $ this -> proc -> write ( $ c ) ; } } | Called when new piece of request s body is received . |
56,129 | public function onWrite ( $ process ) { if ( $ this -> attrs -> stdin_done && ( $ this -> proc -> writeState === false ) ) { $ this -> proc -> closeWrite ( ) ; } } | Called when the request aborted . |
56,130 | public function attachTo ( \ PHPDaemon \ Network \ Pool $ pool ) { $ this -> pool = $ pool ; $ this -> pool -> attachBound ( $ this ) ; } | Attach to ConnectionPool |
56,131 | public function disable ( ) { if ( ! $ this -> enabled ) { return ; } $ this -> enabled = false ; if ( $ this -> ev instanceof \ Event ) { $ this -> ev -> del ( ) ; } elseif ( $ this -> ev instanceof \ EventListener ) { $ this -> ev -> disable ( ) ; } } | Disable all events of sockets |
56,132 | public function close ( ) { if ( isset ( $ this -> ev ) ) { $ this -> ev = null ; } if ( $ this -> pid !== posix_getpid ( ) ) { return ; } if ( is_resource ( $ this -> fd ) ) { socket_close ( $ this -> fd ) ; } } | Close each of binded sockets . |
56,133 | public static function netMatch ( $ CIDR , $ IP ) { if ( is_array ( $ CIDR ) ) { foreach ( $ CIDR as & $ v ) { if ( self :: netMatch ( $ v , $ IP ) ) { return true ; } } return false ; } $ e = explode ( '/' , $ CIDR , 2 ) ; if ( ! isset ( $ e [ 1 ] ) ) { return $ e [ 0 ] === $ IP ; } return ( ip2long ( $ IP ) & ~ ( ( 1... | Checks if the CIDR - mask matches the IP |
56,134 | public static function parse ( $ file , $ target , $ included = false ) { if ( in_array ( $ file , static :: $ stack ) ) { throw new InfiniteRecursion ; } static :: $ stack [ ] = $ file ; $ parser = new static ( $ file , $ target , $ included ) ; array_pop ( static :: $ stack ) ; return $ parser ; } | Parse config file |
56,135 | protected function purgeScope ( $ scope ) { foreach ( $ scope as $ name => $ obj ) { if ( $ obj instanceof Generic ) { if ( $ obj -> source === 'config' && ( $ obj -> revision < $ this -> revision ) ) { if ( ! $ obj -> resetToDefault ( ) ) { unset ( $ scope -> { $ name } ) ; } } } elseif ( $ obj instanceof Section ) { ... | Removes old config parts after updating . |
56,136 | public function raiseError ( $ msg , $ level = 'emerg' , $ line = null , $ col = null ) { if ( $ level === 'emerg' ) { $ this -> erroneous = true ; } if ( $ line === null ) { $ line = $ this -> line ; } if ( $ col === null ) { $ col = $ this -> col - 1 ; } Daemon :: log ( '[conf#' . $ level . '][' . $ this -> file . ' ... | Raises error message . |
56,137 | protected function getCurrentChar ( ) { $ c = substr ( $ this -> data , $ this -> p , 1 ) ; if ( $ c === "\n" ) { ++ $ this -> line ; $ this -> col = 1 ; } else { ++ $ this -> col ; } return $ c ; } | Current character . |
56,138 | public function watch ( ) { if ( $ this -> inotify ) { $ events = inotify_read ( $ this -> inotify ) ; if ( ! $ events ) { return ; } foreach ( $ events as $ ev ) { $ path = $ this -> descriptors [ $ ev [ 'wd' ] ] ; if ( ! isset ( $ this -> files [ $ path ] ) ) { continue ; } $ this -> onFileChanged ( $ path ) ; } } el... | Check the file system triggered by timer |
56,139 | public function rmWatch ( $ path , $ cb ) { $ path = realpath ( $ path ) ; if ( ! isset ( $ this -> files [ $ path ] ) ) { return false ; } if ( ( $ k = array_search ( $ cb , $ this -> files [ $ path ] , true ) ) !== false ) { unset ( $ this -> files [ $ path ] [ $ k ] ) ; } if ( sizeof ( $ this -> files [ $ path ] ) =... | Cancels your subscription on object in FS |
56,140 | public function addWatch ( $ path , $ cb , $ flags = null ) { $ path = realpath ( $ path ) ; if ( ! isset ( $ this -> files [ $ path ] ) ) { $ this -> files [ $ path ] = [ ] ; if ( $ this -> inotify ) { $ this -> descriptors [ inotify_add_watch ( $ this -> inotify , $ path , $ flags ? : IN_MODIFY ) ] = $ path ; } } $ t... | Adds your subscription on object in FS |
56,141 | public static function getAuthKey ( $ username , $ password , $ nonce ) { return md5 ( $ nonce . $ username . md5 ( $ username . ':mongo:' . $ password ) ) ; } | Generates auth . key |
56,142 | public function addServer ( $ url , $ weight = null , $ mock = null ) { $ this -> servers [ $ url ] = $ weight ; } | Adds mongo server |
56,143 | public function auth ( $ p , $ cb ) { if ( ! isset ( $ p [ 'opts' ] ) ) { $ p [ 'opts' ] = 0 ; } $ query = [ 'authenticate' => 1 , 'user' => $ p [ 'user' ] , 'nonce' => $ p [ 'nonce' ] , 'key' => self :: getAuthKey ( $ p [ 'user' ] , $ p [ 'password' ] , $ p [ 'nonce' ] ) , ] ; if ( $ this -> safeMode ) { static :: saf... | Sends authenciation packet |
56,144 | public function lastError ( $ db , $ cb , $ params = [ ] , $ conn = null ) { $ e = explode ( '.' , $ db , 2 ) ; $ params [ 'getlasterror' ] = 1 ; $ cb = CallbackWrapper :: wrap ( $ cb ) ; try { $ this -> request ( self :: OP_QUERY , pack ( 'V' , 0 ) . $ e [ 0 ] . '.$cmd' . "\x00" . pack ( 'VV' , 0 , - 1 ) . bson_encode... | Gets last error |
56,145 | public function evaluate ( $ code , $ cb ) { $ p = [ ] ; if ( ! isset ( $ p [ 'offset' ] ) ) { $ p [ 'offset' ] = 0 ; } if ( ! isset ( $ p [ 'limit' ] ) ) { $ p [ 'limit' ] = - 1 ; } if ( ! isset ( $ p [ 'opts' ] ) ) { $ p [ 'opts' ] = 0 ; } if ( ! isset ( $ p [ 'db' ] ) ) { $ p [ 'db' ] = $ this -> dbname ; } $ cb = C... | Evaluates a code on the server side |
56,146 | public function distinct ( $ p , $ cb ) { $ this -> _params ( $ p ) ; $ e = explode ( '.' , $ p [ 'col' ] , 2 ) ; $ query = [ 'distinct' => $ e [ 1 ] , 'key' => $ p [ 'key' ] , ] ; if ( isset ( $ p [ $ k = 'rp' ] ) ) { $ v = $ p [ $ k ] ; if ( is_string ( $ v ) ) { $ v = [ 'mode' => $ v ] ; } $ query [ '$readPreference... | Returns distinct values of the property |
56,147 | public function killCursors ( $ cursors , $ conn ) { if ( ! $ cursors ) { $ cursors = [ ] ; } $ this -> request ( self :: OP_KILL_CURSORS , "\x00\x00\x00\x00" . pack ( 'V' , sizeof ( $ cursors ) ) . implode ( '' , $ cursors ) , false , $ conn ) ; } | Sends a request to kill certain cursors on the server side |
56,148 | public function remove ( $ col , $ cond = [ ] , $ cb = null , $ params = [ ] ) { if ( mb_orig_strpos ( $ col , '.' ) === false ) { $ col = $ this -> dbname . '.' . $ col ; } if ( is_string ( $ cond ) ) { $ cond = new \ MongoCode ( $ cond ) ; } if ( $ this -> safeMode && is_array ( $ cond ) ) { static :: safeModeEnc ( $... | Remove objects from collection |
56,149 | public function getCollection ( $ col ) { if ( mb_orig_strpos ( $ col , '.' ) === false ) { $ col = $ this -> dbname . '.' . $ col ; } else { $ collName = explode ( '.' , $ col , 2 ) ; } if ( isset ( $ this -> collections [ $ col ] ) ) { return $ this -> collections [ $ col ] ; } return $ this -> collections [ $ col ] ... | Returns an object of collection |
56,150 | public static function buildUrl ( $ mixed ) { if ( is_string ( $ mixed ) ) { return $ mixed ; } if ( ! is_array ( $ mixed ) ) { return false ; } $ url = '' ; $ buf = [ ] ; $ queryDelimiter = '?' ; $ mixed [ ] = '' ; foreach ( $ mixed as $ k => $ v ) { if ( is_int ( $ k ) || ctype_digit ( $ k ) ) { if ( sizeof ( $ buf )... | Builds URL from array |
56,151 | public function destroy ( $ notify = false ) { if ( $ this -> destroyed ) { return false ; } $ this -> destroyed = true ; if ( $ notify ) { if ( $ this -> callback ) { $ func = $ this -> callback ; $ func ( $ this ) ; } } unset ( $ this -> conn -> cursors [ $ this -> id ] ) ; return true ; } | Destroys the cursors |
56,152 | public function cleanupDeferredEventHandlers ( ) { foreach ( $ this as $ key => $ property ) { if ( $ property instanceof DeferredEvent ) { $ property -> cleanup ( ) ; $ this -> { $ key } = null ; } } } | Cleans up events |
56,153 | public function sendCommand ( $ commandName , $ payload , $ cb = null ) { $ pct = implode ( static :: ARGS_DELIMITER , array_map ( function ( $ item ) { return ! is_scalar ( $ item ) ? serialize ( $ item ) : $ item ; } , ( array ) $ payload ) ) ; $ this -> onResponse -> push ( $ cb ) ; $ this -> write ( pack ( static :... | Send a command |
56,154 | public function submitJob ( $ params , $ cb = null ) { $ closure = function ( ) use ( & $ params , $ cb ) { $ this -> sendCommand ( 'SUBMIT_JOB' . ( isset ( $ params [ 'pri' ] ) ? '_ ' . strtoupper ( $ params [ 'pri' ] ) : '' ) . ( isset ( $ params [ 'bg' ] ) && $ params [ 'bg' ] ? '_BG' : '' ) , [ $ params [ 'function... | Function run task and wait result in callback |
56,155 | public static function get ( $ path ) { $ ext = strtolower ( pathinfo ( $ path , PATHINFO_EXTENSION ) ) ; if ( ! isset ( self :: $ fileTypes [ $ ext ] ) ) { return false ; } return self :: $ fileTypes [ $ ext ] ; } | Returns MIME type of the given file |
56,156 | public function setRouteOptions ( $ path , $ opts ) { $ routeName = ltrim ( $ path , '/' ) ; if ( ! isset ( $ this -> routes [ $ routeName ] ) ) { Daemon :: log ( __METHOD__ . ': Route \'' . $ path . '\' is not found.' ) ; return false ; } $ this -> routeOptions [ $ routeName ] = $ opts ; return true ; } | Sets an array of options associated to the route |
56,157 | public function getRouteOptions ( $ path ) { $ routeName = ltrim ( $ path , '/' ) ; if ( ! isset ( $ this -> routeOptions [ $ routeName ] ) ) { return [ ] ; } return $ this -> routeOptions [ $ routeName ] ; } | Return options by route |
56,158 | public function addRoute ( $ path , $ cb ) { $ routeName = ltrim ( $ path , '/' ) ; if ( isset ( $ this -> routes [ $ routeName ] ) ) { Daemon :: log ( __METHOD__ . ': Route \'' . $ path . '\' is already defined.' ) ; return false ; } $ this -> routes [ $ routeName ] = $ cb ; return true ; } | Adds a route if it doesn t exist already . |
56,159 | public function remove ( $ cond = [ ] , $ cb = null , $ params = null ) { $ this -> pool -> remove ( $ this -> name , $ cond , $ cb ) ; } | Removes objects from collection |
56,160 | public function executeOne ( ... $ args ) { if ( $ this -> isEmpty ( ) ) { return false ; } $ cb = $ this -> extract ( ) ; if ( $ cb ) { $ cb ( ... $ args ) ; } return true ; } | Executes one callback from the top of queue with arbitrary arguments |
56,161 | public function executeAll ( ... $ args ) { if ( $ this -> isEmpty ( ) ) { return 0 ; } $ n = 0 ; do { $ cb = $ this -> extract ( ) ; if ( $ cb ) { $ cb ( ... $ args ) ; ++ $ n ; } } while ( ! $ this -> isEmpty ( ) ) ; return $ n ; } | Executes all callbacks from the top of queue to bottom with arbitrary arguments |
56,162 | public function sendFrame ( $ payload , $ type = Pool :: TYPE_TEXT , $ isMasked = true ) { $ payloadLength = mb_orig_strlen ( $ payload ) ; if ( $ payloadLength > $ this -> pool -> maxAllowedPacket ) { Daemon :: $ process -> log ( 'max-allowed-packet (' . $ this -> pool -> config -> maxallowedpacket -> getHumanValue ( ... | Send frame to WebSocket server |
56,163 | public function _addContact ( $ jid , $ subscription , $ name = '' , $ groups = [ ] ) { $ contact = [ 'jid' => $ jid , 'subscription' => $ subscription , 'name' => $ name , 'groups' => $ groups ] ; if ( $ this -> isContact ( $ jid ) ) { $ this -> roster_array [ $ jid ] [ 'contact' ] = $ contact ; } else { $ this -> ros... | Add given contact to roster |
56,164 | public static function start ( ) { if ( Bootstrap :: $ pid && Thread \ Generic :: ifExistsByPid ( Bootstrap :: $ pid ) ) { Daemon :: log ( '[START] phpDaemon with pid-file \'' . Daemon :: $ config -> pidfile -> value . '\' is running already (PID ' . Bootstrap :: $ pid . ')' ) ; exit ( 6 ) ; } Daemon :: init ( ) ; $ pi... | Start master . |
56,165 | public static function stop ( $ mode = 1 ) { $ ok = Bootstrap :: $ pid && posix_kill ( Bootstrap :: $ pid , $ mode === 3 ? SIGINT : ( ( $ mode === 4 ) ? SIGTSTP : SIGTERM ) ) ; if ( ! $ ok ) { echo '[WARN]. It seems that phpDaemon is not running' . ( Bootstrap :: $ pid ? ' (PID ' . Bootstrap :: $ pid . ')' : '' ) . ".\... | Stop script . |
56,166 | public static function getArgs ( $ args ) { $ out = [ ] ; $ last_arg = null ; for ( $ i = 1 , $ il = sizeof ( $ args ) ; $ i < $ il ; ++ $ i ) { if ( preg_match ( '~^--(.+)~' , $ args [ $ i ] , $ match ) ) { $ parts = explode ( '=' , $ match [ 1 ] ) ; $ key = preg_replace ( '~[^a-z0-9]+~' , '' , $ parts [ 0 ] ) ; if ( ... | Parses command - line arguments . |
56,167 | public function set ( $ key , $ value , $ exp = 0 , $ onResponse = null ) { $ this -> getConnectionByKey ( $ key , function ( $ conn ) use ( $ key , $ value , $ exp , $ onResponse ) { if ( ! $ conn -> connected ) { return ; } if ( $ onResponse !== null ) { $ conn -> onResponse -> push ( $ onResponse ) ; $ conn -> check... | Sets the key |
56,168 | public function delete ( $ key , $ onResponse = null , $ time = 0 ) { $ this -> getConnectionByKey ( $ key , function ( $ conn ) use ( $ key , $ time , $ onResponse ) { if ( ! $ conn -> connected ) { return ; } if ( $ onResponse !== null ) { $ conn -> onResponse -> push ( $ onResponse ) ; $ conn -> checkFree ( ) ; } $ ... | Deletes the key |
56,169 | public function prepend ( $ key , $ value , $ exp = 0 , $ onResponse = null ) { $ this -> getConnectionByKey ( $ key , function ( $ conn ) use ( $ key , $ value , $ exp , $ onResponse ) { if ( ! $ conn -> connected ) { return ; } if ( $ onResponse !== null ) { $ conn -> onResponse -> push ( $ onResponse ) ; $ conn -> s... | Prepends a string to the key s value |
56,170 | public static function diffAsText ( $ datetime1 , $ datetime2 , $ absolute = false ) { if ( ! ( $ datetime1 instanceof \ DateTimeInterface ) ) { $ datetime1 = new static ( $ datetime1 ) ; } if ( ! ( $ datetime2 instanceof \ DateTimeInterface ) ) { $ datetime2 = new static ( $ datetime2 ) ; } $ interval = $ datetime1 ->... | Calculates a difference between two dates |
56,171 | protected function update ( ) { FileSystem :: updateConfig ( ) ; foreach ( Daemon :: $ appInstances as $ app ) { foreach ( $ app as $ appInstance ) { $ appInstance -> handleStatus ( AppInstance :: EVENT_CONFIG_UPDATED ) ; } } } | Reloads additional config - files on - the - fly . |
56,172 | public function sigunknown ( $ signo ) { if ( isset ( Generic :: $ signals [ $ signo ] ) ) { $ sig = Generic :: $ signals [ $ signo ] ; } else { $ sig = 'UNKNOWN' ; } $ this -> log ( 'caught signal #' . $ signo . ' (' . $ sig . ').' ) ; } | Handler of non - known signals . |
56,173 | public function imposeDefault ( $ settings = [ ] ) { foreach ( $ settings as $ name => $ value ) { $ name = strtolower ( str_replace ( '-' , '' , $ name ) ) ; if ( ! isset ( $ this -> { $ name } ) ) { if ( is_scalar ( $ value ) ) { $ this -> { $ name } = new Generic ( $ value ) ; } else { $ this -> { $ name } = $ value... | Impose default config |
56,174 | public static function remove ( $ id ) { if ( isset ( self :: $ list [ $ id ] ) ) { self :: $ list [ $ id ] -> free ( ) ; } } | Removes timer by ID |
56,175 | public function free ( ) { unset ( self :: $ list [ $ this -> id ] ) ; if ( $ this -> ev !== null ) { $ this -> ev -> free ( ) ; $ this -> ev = null ; } } | Frees the timer |
56,176 | public static function cancelTimeout ( $ id ) { if ( isset ( self :: $ list [ $ id ] ) ) { self :: $ list [ $ id ] -> cancel ( ) ; } } | Cancels timer by ID |
56,177 | public function eventCall ( ) { try { $ func = $ this -> cb ; $ func ( $ this ) ; } catch ( \ Exception $ e ) { Daemon :: uncaughtExceptionHandler ( $ e ) ; } } | Called when timer is triggered |
56,178 | public function onSessionStartEvent ( ) { return function ( $ sessionStartEvent ) { $ name = ini_get ( 'session.name' ) ; $ sid = $ this -> getCookieStr ( $ name ) ; if ( $ sid === '' ) { $ this -> sessionStartNew ( function ( $ success ) use ( $ sessionStartEvent ) { $ sessionStartEvent -> setResult ( $ success ) ; } ... | Deferred event onSessionStart |
56,179 | public function onSessionReadEvent ( ) { return function ( $ sessionEvent ) { $ name = ini_get ( 'session.name' ) ; $ sid = $ this -> getCookieStr ( $ name ) ; if ( $ sid === '' ) { $ sessionEvent -> setResult ( false ) ; return ; } if ( $ this -> getSessionState ( ) !== null ) { $ sessionEvent -> setResult ( true ) ; ... | Deferred event onSessionRead |
56,180 | public function sessionCommit ( $ cb = null ) { if ( ! $ this -> sessionFp || $ this -> sessionFlushing ) { if ( $ cb ) { $ cb ( false ) ; } return ; } $ this -> sessionFlushing = true ; $ data = $ this -> sessionEncode ( ) ; $ l = mb_orig_strlen ( $ data ) ; $ cb = CallbackWrapper :: wrap ( $ cb ) ; $ this -> sessionF... | Commmit session data |
56,181 | protected function sessionStartNew ( $ cb = null ) { FileSystem :: tempnam ( session_save_path ( ) , $ this -> sessionPrefix , function ( $ fp ) use ( $ cb ) { if ( ! $ fp ) { $ cb ( false ) ; return ; } $ this -> sessionFp = $ fp ; $ this -> sessionId = substr ( basename ( $ fp -> path ) , mb_orig_strlen ( $ this -> s... | Start new session |
56,182 | protected function sessionEncode ( ) { $ type = ini_get ( 'session.serialize_handler' ) ; if ( $ type === 'php' ) { return $ this -> serializePHP ( $ this -> getSessionState ( ) ) ; } if ( $ type === 'php_binary' ) { return igbinary_serialize ( $ this -> getSessionState ( ) ) ; } return false ; } | Encodes session data |
56,183 | protected function sessionDecode ( $ str ) { $ type = ini_get ( 'session.serialize_handler' ) ; if ( $ type === 'php' ) { $ this -> setSessionState ( $ this -> unserializePHP ( $ str ) ) ; return true ; } if ( $ type === 'php_binary' ) { $ this -> setSessionState ( igbinary_unserialize ( $ str ) ) ; return true ; } ret... | Decodes session data |
56,184 | public function open ( $ segno = 0 , $ create = false ) { if ( isset ( $ this -> segments [ $ segno ] ) ) { return $ this -> segments [ $ segno ] ; } $ key = $ this -> key + $ segno ; if ( ! $ create ) { $ shm = @ shmop_open ( $ key , 'w' , 0 , 0 ) ; } else { $ shm = @ shmop_open ( $ key , 'w' , 0 , 0 ) ; if ( $ shm ) ... | Opens segment of shared memory |
56,185 | public function write ( $ data , $ offset ) { $ segno = floor ( $ offset / $ this -> segsize ) ; if ( ! isset ( $ this -> segments [ $ segno ] ) ) { if ( ! $ this -> open ( $ segno , true ) ) { return false ; } } $ sOffset = $ offset % $ this -> segsize ; $ d = $ this -> segsize - ( $ sOffset + mb_orig_strlen ( $ data ... | Write to shared memory |
56,186 | public function read ( $ offset , $ length = 1 ) { $ ret = '' ; $ segno = floor ( $ offset / $ this -> segsize ) ; $ sOffset = $ offset % $ this -> segsize ; while ( true ) { if ( ! isset ( $ this -> segments [ $ segno ] ) ) { if ( ! $ this -> open ( $ segno ) ) { goto ret ; } } $ ret .= shmop_read ( $ this -> segments... | Read from shared memory |
56,187 | public function bindSockets ( $ addrs = [ ] , $ max = 0 ) { if ( is_string ( $ addrs ) ) { $ addrs = array_map ( 'trim' , explode ( ',' , $ addrs ) ) ; } $ n = 0 ; foreach ( $ addrs as $ addr ) { if ( $ this -> bindSocket ( $ addr ) ) { ++ $ n ; } if ( $ max > 0 && ( $ n >= $ max ) ) { return $ n ; } } return $ n ; } | Bind given sockets |
56,188 | public function bindSocket ( $ uri ) { $ u = \ PHPDaemon \ Config \ _Object :: parseCfgUri ( $ uri ) ; $ scheme = $ u [ 'scheme' ] ; if ( $ scheme === 'unix' ) { $ socket = new \ PHPDaemon \ BoundSocket \ UNIX ( $ u ) ; } elseif ( $ scheme === 'udp' ) { $ socket = new \ PHPDaemon \ BoundSocket \ UDP ( $ u ) ; if ( isse... | Bind given socket |
56,189 | public function inheritFromRequest ( $ req , $ oldConn ) { if ( ! $ oldConn || ! $ req ) { return false ; } $ class = $ this -> connectionClass ; $ conn = new $ class ( null , $ this ) ; $ this -> attach ( $ conn ) ; $ conn -> setFd ( $ oldConn -> getFd ( ) , $ oldConn -> getBev ( ) ) ; $ oldConn -> unsetFd ( ) ; $ old... | Called when a request to HTTP - server looks like another connection |
56,190 | public function sendPacket ( $ type , $ packet ) { $ header = $ type . pack ( 'N' , mb_orig_strlen ( $ packet ) + 4 ) ; $ this -> write ( $ header ) ; $ this -> write ( $ packet ) ; if ( $ this -> pool -> config -> protologging -> value ) { Daemon :: log ( 'Client . Debug :: exportBytes ( $ header . $ packet ) . "\n\n... | Send a packet |
56,191 | public function parseEncodedBinary ( & $ s , & $ p ) { $ f = ord ( mb_orig_substr ( $ s , $ p , 1 ) ) ; ++ $ p ; if ( $ f <= 250 ) { return $ f ; } if ( $ s === 251 ) { return null ; } if ( $ s === 255 ) { return false ; } if ( $ f === 252 ) { $ o = $ p ; $ p += 2 ; return $ this -> bytes2int ( mb_orig_substr ( $ s , $... | Parses length - encoded binary |
56,192 | public function selectDB ( $ name ) { $ this -> dbname = $ name ; if ( $ this -> state !== 1 ) { return $ this -> query ( 'USE `' . $ name . '`' ) ; } return true ; } | Set default database name |
56,193 | public function decodeNULstrings ( $ data , $ limit = 1 , & $ p = 0 ) { $ r = [ ] ; for ( $ i = 0 ; $ i < $ limit ; ++ $ i ) { $ pos = mb_orig_strpos ( $ data , "\x00" , $ p ) ; if ( $ pos === false ) { break ; } $ r [ ] = mb_orig_substr ( $ data , $ p , $ pos - $ p ) ; $ p = $ pos + 1 ; } return $ r ; } | Decode strings from the NUL - terminated representation |
56,194 | public static function initSettings ( ) { Daemon :: $ version = file_get_contents ( 'VERSION' , true ) ; Daemon :: $ config = new Config \ _Object ; if ( ! defined ( 'SO_REUSEPORT' ) && mb_orig_strpos ( php_uname ( 's' ) , 'BSD' ) !== false ) { define ( 'SO_REUSEPORT' , 0x200 ) ; } } | Loads default setting . |
56,195 | public static function glob ( $ pattern , $ flags = 0 ) { $ r = [ ] ; foreach ( explode ( ':' , get_include_path ( ) ) as $ path ) { $ r = array_merge ( $ r , glob ( $ p = $ path . '/' . $ pattern , $ flags ) ) ; } return array_unique ( $ r ) ; } | Glob function with support of include_path |
56,196 | public static function uniqid ( ) { static $ n = 0 ; return str_shuffle ( md5 ( str_shuffle ( microtime ( true ) . chr ( mt_rand ( 0 , 0xFF ) ) . Daemon :: $ process -> getPid ( ) . chr ( mt_rand ( 0 , 0xFF ) ) . ( ++ $ n ) . mt_rand ( 0 , mt_getrandmax ( ) ) ) ) ) ; } | Generate a unique ID . |
56,197 | public static function checkAutoGC ( ) { if ( ( Daemon :: $ config -> autogc -> value > 0 ) && ( Daemon :: $ process -> counterGC > 0 ) && ( Daemon :: $ process -> counterGC >= Daemon :: $ config -> autogc -> value ) ) { Daemon :: $ process -> counterGC = 0 ; return true ; } return false ; } | Check if we need to run automatic garbage collector |
56,198 | public static function init ( ) { Daemon :: $ startTime = time ( ) ; set_time_limit ( 0 ) ; Daemon :: $ defaultErrorLevel = error_reporting ( ) ; Daemon :: $ restrictErrorControl = ( bool ) Daemon :: $ config -> restricterrorcontrol -> value ; ob_start ( [ '\PHPDaemon\Core\Daemon' , 'outputFilter' ] ) ; set_error_handl... | Performs initial actions . |
56,199 | public static function lintFile ( $ filename ) { if ( ! file_exists ( $ filename ) ) { return false ; } if ( self :: supported ( self :: SUPPORT_RUNKIT_SANDBOX ) ) { return runkit_lint_file ( $ filename ) ; } $ cmd = 'php -l ' . escapeshellcmd ( $ filename ) . ' 2>&1' ; exec ( $ cmd , $ output , $ retcode ) ; return 0 ... | Check file syntax via runkit_lint_file if supported or via php - l |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.