idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
53,200 | public static function createFromEnvironment ( array $ server ) : self { [ $ user , $ pass ] = self :: fetchUserInfo ( $ server ) ; [ $ host , $ port ] = self :: fetchHostname ( $ server ) ; [ $ path , $ query ] = self :: fetchRequestUri ( $ server ) ; return Uri :: createFromComponents ( [ 'scheme' => self :: fetchSch... | Create a new instance from the environment . |
53,201 | private static function fetchScheme ( array $ server ) : string { $ server += [ 'HTTPS' => '' ] ; $ res = filter_var ( $ server [ 'HTTPS' ] , FILTER_VALIDATE_BOOLEAN , FILTER_NULL_ON_FAILURE ) ; return $ res !== false ? 'https' : 'http' ; } | Returns the environment scheme . |
53,202 | private static function fetchUserInfo ( array $ server ) : array { $ server += [ 'PHP_AUTH_USER' => null , 'PHP_AUTH_PW' => null , 'HTTP_AUTHORIZATION' => '' ] ; $ user = $ server [ 'PHP_AUTH_USER' ] ; $ pass = $ server [ 'PHP_AUTH_PW' ] ; if ( 0 === strpos ( strtolower ( $ server [ 'HTTP_AUTHORIZATION' ] ) , 'basic' )... | Returns the environment user info . |
53,203 | private static function fetchHostname ( array $ server ) : array { $ server += [ 'SERVER_PORT' => null ] ; if ( null !== $ server [ 'SERVER_PORT' ] ) { $ server [ 'SERVER_PORT' ] = ( int ) $ server [ 'SERVER_PORT' ] ; } if ( isset ( $ server [ 'HTTP_HOST' ] ) ) { preg_match ( ',^(?<host>(\[.*\]|[^:])*)(\:(?<port>[^/?\#... | Returns the environment host . |
53,204 | private static function fetchRequestUri ( array $ server ) : array { $ server += [ 'IIS_WasUrlRewritten' => null , 'UNENCODED_URL' => '' , 'PHP_SELF' => '' , 'QUERY_STRING' => null ] ; if ( '1' === $ server [ 'IIS_WasUrlRewritten' ] && '' !== $ server [ 'UNENCODED_URL' ] ) { return explode ( '?' , $ server [ 'UNENCODED... | Returns the environment path . |
53,205 | private function setAuthority ( ) : ? string { $ authority = null ; if ( null !== $ this -> user_info ) { $ authority = $ this -> user_info . '@' ; } if ( null !== $ this -> host ) { $ authority .= $ this -> host ; } if ( null !== $ this -> port ) { $ authority .= ':' . $ this -> port ; } return $ authority ; } | Generate the URI authority part . |
53,206 | private function formatPath ( string $ path ) : string { $ path = $ this -> formatDataPath ( $ path ) ; static $ pattern = '/(?:[^' . self :: REGEXP_CHARS_UNRESERVED . self :: REGEXP_CHARS_SUBDELIM . '%:@\/}{]++\|%(?![A-Fa-f0-9]{2}))/' ; $ path = ( string ) preg_replace_callback ( $ pattern , [ Uri :: class , 'urlEncod... | Format the Path component . |
53,207 | private function formatDataPath ( string $ path ) : string { if ( 'data' !== $ this -> scheme ) { return $ path ; } if ( '' == $ path ) { return 'text/plain;charset=us-ascii,' ; } if ( false === mb_detect_encoding ( $ path , 'US-ASCII' , true ) || false === strpos ( $ path , ',' ) ) { throw new SyntaxError ( sprintf ( ... | Filter the Path component . |
53,208 | private function assertValidPath ( string $ mimetype , string $ parameters , string $ data ) : void { if ( 1 !== preg_match ( self :: REGEXP_MIMETYPE , $ mimetype ) ) { throw new SyntaxError ( sprintf ( 'The path mimetype `%s` is invalid' , $ mimetype ) ) ; } $ is_binary = 1 === preg_match ( self :: REGEXP_BINARY , $ p... | Assert the path is a compliant with RFC2397 . |
53,209 | private function formatQueryAndFragment ( ? string $ component ) : ? string { if ( null === $ component || '' === $ component ) { return $ component ; } static $ pattern = '/(?:[^' . self :: REGEXP_CHARS_UNRESERVED . self :: REGEXP_CHARS_SUBDELIM . '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/' ; return preg_replace_callback ( $ p... | Format the Query or the Fragment component . |
53,210 | private function assertValidState ( ) : void { if ( null !== $ this -> authority && ( '' !== $ this -> path && '/' !== $ this -> path [ 0 ] ) ) { throw new SyntaxError ( 'If an authority is present the path must be empty or start with a `/`' ) ; } if ( null === $ this -> authority && 0 === strpos ( $ this -> path , '//... | assert the URI internal state is valid . |
53,211 | private function isUriWithSchemeAndPathOnly ( ) { return null === $ this -> authority && null === $ this -> query && null === $ this -> fragment ; } | URI validation for URI schemes which allows only scheme and path components . |
53,212 | private function isUriWithSchemeHostAndPathOnly ( ) { return null === $ this -> user_info && null === $ this -> port && null === $ this -> query && null === $ this -> fragment && ! ( '' != $ this -> scheme && null === $ this -> host ) ; } | URI validation for URI schemes which allows only scheme host and path components . |
53,213 | private function getUriString ( ? string $ scheme , ? string $ authority , string $ path , ? string $ query , ? string $ fragment ) : string { if ( null !== $ scheme ) { $ scheme = $ scheme . ':' ; } if ( null !== $ authority ) { $ authority = '//' . $ authority ; } if ( null !== $ query ) { $ query = '?' . $ query ; }... | Generate the URI string representation from its components . |
53,214 | private function validate ( UriInterface $ uri ) : void { $ scheme = $ uri -> getScheme ( ) ; if ( null === $ scheme && '' === $ uri -> getHost ( ) ) { throw new SyntaxError ( sprintf ( 'an URI without scheme can not contains a empty host string according to PSR-7: %s' , ( string ) $ uri ) ) ; } $ port = $ uri -> getPo... | Validate the submitted uri against PSR - 7 UriInterface . |
53,215 | protected function read ( ) { $ n = 0 ; while ( $ info = curl_multi_info_read ( $ this -> mh ) ) { $ n ++ ; $ request = $ this -> queue [ ( int ) $ info [ 'handle' ] ] ; $ result = $ info [ 'result' ] ; curl_multi_remove_handle ( $ this -> mh , $ request -> getHandle ( ) ) ; unset ( $ this -> running [ $ request -> get... | Processes handles which are ready and removes them from pool . |
53,216 | public function socketPerform ( ) { if ( $ this -> count ( ) == 0 ) { throw new Exception ( 'Cannot perform if there are no requests in queue.' ) ; } $ notRunning = $ this -> getRequestsNotRunning ( ) ; do { foreach ( $ notRunning as $ request ) { $ this -> getDefaultOptions ( ) -> applyTo ( $ request ) ; $ request -> ... | Download available data on socket . |
53,217 | public function applyTo ( Request $ request ) { if ( ! empty ( $ this -> data ) ) { curl_setopt_array ( $ request -> getHandle ( ) , $ this -> data ) ; } return $ this ; } | Applies options to Request object |
53,218 | public function getHostname ( ) { if ( is_null ( $ this -> hostname ) ) { $ this -> hostname = gethostbyaddr ( $ this -> ip ) ; } return $ this -> hostname ; } | Gets the IP hostname |
53,219 | public static function createId ( $ queue , $ class , $ data = null , $ run_at = 0 ) { $ id = dechex ( crc32 ( $ queue ) ) . dechex ( microtime ( true ) * 1000 ) . md5 ( json_encode ( $ class ) . json_encode ( $ data ) . $ run_at . uniqid ( '' , true ) ) ; return substr ( $ id , 0 , self :: ID_LENGTH ) ; } | Create a new job id |
53,220 | public static function load ( $ id ) { $ packet = Redis :: instance ( ) -> hgetall ( self :: redisKey ( $ id ) ) ; if ( empty ( $ packet ) or empty ( $ packet [ 'queue' ] ) or ! count ( $ payload = json_decode ( $ packet [ 'payload' ] , true ) ) ) { return null ; } return new static ( $ packet [ 'queue' ] , $ payload [... | Load a job from id |
53,221 | public static function loadPayload ( $ queue , $ payload ) { $ payload = json_decode ( $ payload , true ) ; if ( ! is_array ( $ payload ) or ! count ( $ payload ) ) { throw new \ InvalidArgumentException ( 'Supplied $payload must be a json encoded array.' ) ; } return new static ( $ queue , $ payload [ 'id' ] , $ paylo... | Load a job from the Redis payload |
53,222 | public function queue ( ) { if ( Event :: fire ( Event :: JOB_QUEUE , $ this ) === false ) { return false ; } $ this -> redis -> sadd ( Queue :: redisKey ( ) , $ this -> queue ) ; $ status = $ this -> redis -> rpush ( Queue :: redisKey ( $ this -> queue ) , $ this -> payload ) ; if ( $ status < 1 ) { return false ; } $... | Save the job to Redis queue |
53,223 | public function delay ( $ time ) { if ( Event :: fire ( Event :: JOB_DELAY , array ( $ this , $ time ) ) === false ) { return false ; } $ this -> redis -> sadd ( Queue :: redisKey ( ) , $ this -> queue ) ; $ status = $ this -> redis -> zadd ( Queue :: redisKey ( $ this -> queue , 'delayed' ) , $ time , $ this -> payloa... | Save the job to Redis delayed queue |
53,224 | public function perform ( ) { Stats :: decr ( 'queued' , 1 ) ; Stats :: decr ( 'queued' , 1 , Queue :: redisKey ( $ this -> queue , 'stats' ) ) ; if ( Event :: fire ( Event :: JOB_PERFORM , $ this ) === false ) { $ this -> cancel ( ) ; return false ; } $ this -> run ( ) ; $ retval = true ; try { $ instance = $ this -> ... | Perform the job |
53,225 | public function getInstance ( ) { if ( ! is_null ( $ this -> instance ) ) { return $ this -> instance ; } if ( ! class_exists ( $ this -> class ) ) { throw new \ RuntimeException ( 'Could not find job class "' . $ this -> class . '"' ) ; } if ( ! method_exists ( $ this -> class , $ this -> method ) or ! is_callable ( a... | Get the instantiated object for this job that will be performing work |
53,226 | public function run ( ) { $ this -> setStatus ( Job :: STATUS_RUNNING ) ; $ this -> redis -> zadd ( Queue :: redisKey ( $ this -> queue , 'running' ) , time ( ) , $ this -> payload ) ; Stats :: incr ( 'running' , 1 ) ; Stats :: incr ( 'running' , 1 , Queue :: redisKey ( $ this -> queue , 'stats' ) ) ; Event :: fire ( E... | Mark the current job running |
53,227 | protected function stopped ( ) { $ this -> redis -> zrem ( Queue :: redisKey ( $ this -> queue , 'running' ) , $ this -> payload ) ; Stats :: decr ( 'running' , 1 ) ; Stats :: decr ( 'running' , 1 , Queue :: redisKey ( $ this -> queue , 'stats' ) ) ; } | Mark the current job stopped This is an internal function as the job is either completed cancelled or failed |
53,228 | public function complete ( ) { $ this -> stopped ( ) ; $ this -> setStatus ( Job :: STATUS_COMPLETE ) ; $ this -> redis -> zadd ( Queue :: redisKey ( $ this -> queue , 'processed' ) , time ( ) , $ this -> payload ) ; Stats :: incr ( 'processed' , 1 ) ; Stats :: incr ( 'processed' , 1 , Queue :: redisKey ( $ this -> que... | Mark the current job as complete |
53,229 | public function cancel ( ) { $ this -> stopped ( ) ; $ this -> setStatus ( Job :: STATUS_CANCELLED ) ; $ this -> redis -> zadd ( Queue :: redisKey ( $ this -> queue , 'cancelled' ) , time ( ) , $ this -> payload ) ; Stats :: incr ( 'cancelled' , 1 ) ; Stats :: incr ( 'cancelled' , 1 , Queue :: redisKey ( $ this -> queu... | Mark the current job as cancelled |
53,230 | public function fail ( \ Exception $ e ) { $ this -> stopped ( ) ; $ this -> setStatus ( Job :: STATUS_FAILED , $ e ) ; $ packet = $ this -> getPacket ( ) ; $ failed_payload = array_merge ( json_decode ( $ this -> payload , true ) , array ( 'worker' => $ packet [ 'worker' ] , 'started' => $ packet [ 'started' ] , 'fini... | Mark the current job as having failed |
53,231 | public function failError ( ) { if ( ( $ packet = $ this -> getPacket ( ) ) and $ packet [ 'status' ] !== Job :: STATUS_FAILED and ( $ e = json_decode ( $ packet [ 'exception' ] , true ) ) ) { return $ e [ 'error' ] ; } return 'Unknown exception' ; } | Returns the fail error for the job |
53,232 | protected function createPayload ( ) { if ( $ this -> data instanceof Closure ) { $ closure = serialize ( new Helpers \ SerializableClosure ( $ this -> data ) ) ; $ data = compact ( 'closure' ) ; } else { $ data = $ this -> data ; } return json_encode ( array ( 'id' => $ this -> id , 'class' => $ this -> class , 'data'... | Create a payload string from the given job and data |
53,233 | public function setStatus ( $ status , \ Exception $ e = null ) { if ( ! ( $ packet = $ this -> getPacket ( ) ) ) { $ packet = array ( 'id' => $ this -> id , 'queue' => $ this -> queue , 'payload' => $ this -> payload , 'worker' => '' , 'status' => $ status , 'created' => microtime ( true ) , 'updated' => microtime ( t... | Update the status indicator for the current job with a new status |
53,234 | public function getPacket ( ) { if ( $ packet = $ this -> redis -> hgetall ( self :: redisKey ( $ this ) ) ) { return $ packet ; } return false ; } | Fetch the packet for the job being monitored . |
53,235 | public static function cleanup ( array $ queues = array ( '*' ) ) { $ cleaned = array ( 'zombie' => 0 , 'processed' => 0 ) ; $ redis = Redis :: instance ( ) ; if ( in_array ( '*' , $ queues ) ) { $ queues = ( array ) $ redis -> smembers ( Queue :: redisKey ( ) ) ; sort ( $ queues ) ; } $ workers = $ redis -> smembers (... | Look for any jobs which are running but the worker is dead . Meaning that they are also not running but left in limbo |
53,236 | public static function fromId ( $ id , Logger $ logger = null ) { if ( ! $ id or ! count ( $ packet = Redis :: instance ( ) -> hgetall ( self :: redisKey ( $ id ) ) ) ) { return false ; } $ worker = new static ( explode ( ',' , $ packet [ 'queues' ] ) , $ packet [ 'blocking' ] ) ; $ worker -> setId ( $ id ) ; $ worker ... | Return a worker from it s ID |
53,237 | public function register ( ) { $ this -> log ( 'Registering worker <pop>' . $ this . '</pop>' , Logger :: NOTICE ) ; $ this -> redis -> sadd ( self :: redisKey ( ) , $ this -> id ) ; $ this -> redis -> hmset ( self :: redisKey ( $ this ) , array ( 'started' => microtime ( true ) , 'hostname' => ( string ) $ this -> hos... | Register this worker in Redis and signal handlers that a worker should respond to |
53,238 | public function unregister ( ) { if ( $ this -> child === 0 ) { if ( ( $ error = error_get_last ( ) ) and in_array ( $ error [ 'type' ] , $ this -> shutdownErrors ) ) { $ this -> job -> fail ( new \ ErrorException ( $ error [ 'message' ] , $ error [ 'type' ] , 0 , $ error [ 'file' ] , $ error [ 'line' ] ) ) ; } return ... | Unregister this worker in Redis |
53,239 | public function sigForceShutdown ( $ sig ) { switch ( $ sig ) { case SIGTERM : $ sig = 'TERM' ; break ; case SIGINT : $ sig = 'INT' ; break ; default : $ sig = 'Unknown' ; break ; } $ this -> log ( $ sig . ' received; force shutdown worker' , Logger :: DEBUG ) ; $ this -> forceShutdown ( ) ; } | Signal handler callback for TERM or INT forces shutdown of worker |
53,240 | public function sigWakeUp ( ) { $ this -> log ( 'SIGPIPE received; attempting to wake up' , Logger :: DEBUG ) ; $ this -> redis -> establishConnection ( ) ; Event :: fire ( Event :: WORKER_WAKEUP , $ this ) ; } | Signal handler for SIGPIPE in the event the Redis connection has gone away . Attempts to reconnect to Redis or raises an Exception . |
53,241 | public function setStatus ( $ status ) { $ this -> redis -> hset ( self :: redisKey ( $ this ) , 'status' , $ status ) ; $ oldstatus = $ this -> status ; $ this -> status = $ status ; switch ( $ status ) { case self :: STATUS_NEW : break ; case self :: STATUS_RUNNING : if ( $ oldstatus != self :: STATUS_NEW ) { Event :... | Update the status indicator for the current worker with a new status . |
53,242 | public function queueDelayed ( $ endTime = null , $ startTime = 0 ) { $ startTime = $ startTime ? : 0 ; $ endTime = $ endTime ? : time ( ) ; foreach ( $ this -> resolveQueues ( ) as $ queue ) { $ this -> redis -> multi ( ) ; $ jobs = $ this -> redis -> zrangebyscore ( Queue :: redisKey ( $ queue , 'delayed' ) , $ start... | Find any delayed jobs and add them to the queue if found |
53,243 | public static function hostWorker ( $ id , $ host = null , Logger $ logger = null ) { $ workers = self :: hostWorkers ( $ host ) ; foreach ( $ workers as $ worker ) { if ( ( string ) $ id == ( string ) $ worker and posix_kill ( $ worker -> getPid ( ) , 0 ) ) { return $ worker ; } } return false ; } | Return host worker by id |
53,244 | public function setId ( $ id ) { if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker id after worker has started working' ) ; } $ this -> id = $ id ; } | Set the worker id |
53,245 | public function setQueues ( $ queues ) { if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker queues after worker has started working' ) ; } $ this -> queues = $ queues ; } | Set the worker queues |
53,246 | public function setPid ( $ pid ) { if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker pid after worker has started working' ) ; } $ this -> pid = ( int ) $ pid ; } | Set the worker process id - this is done when worker is loaded from memory |
53,247 | public function setPidFile ( $ pidFile ) { $ dir = realpath ( dirname ( $ pidFile ) ) ; $ filename = basename ( $ pidFile ) ; if ( substr ( $ pidFile , - 1 ) == '/' or $ filename == '.' ) { throw new \ InvalidArgumentException ( 'The pid file "' . $ pidFile . '" must be a valid file path' ) ; } if ( ! is_dir ( $ dir ) ... | Set the worker pid file |
53,248 | public function setHost ( Host $ host ) { $ this -> host = $ host ; if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker host after worker has started working' ) ; } } | Set the queue host |
53,249 | public function setBlocking ( $ blocking ) { if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker blocking after worker has started working' ) ; } $ this -> blocking = ( bool ) $ blocking ; } | Set the queue blocking |
53,250 | public function setInterval ( $ interval ) { if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker interval after worker has started working' ) ; } $ this -> interval = $ interval ; } | Set the worker interval |
53,251 | public function setTimeout ( $ timeout ) { if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker timeout after worker has started working' ) ; } $ this -> timeout = $ timeout ; } | Set the worker queue timeout |
53,252 | public function setMemoryLimit ( $ memoryLimit ) { if ( $ this -> status != self :: STATUS_NEW ) { throw new \ RuntimeException ( 'Cannot set worker memory limit after worker has started working' ) ; } $ this -> memoryLimit = $ memoryLimit ; } | Set the queue memory limit |
53,253 | protected function updateProcLine ( $ status ) { $ status = $ this -> getProcessTitle ( $ status ) ; if ( function_exists ( 'cli_set_process_title' ) && PHP_OS !== 'Darwin' ) { cli_set_process_title ( $ status ) ; return ; } if ( function_exists ( 'setproctitle' ) ) { setproctitle ( $ status ) ; } } | On supported systems update the name of the currently running process to indicate the current state of a worker . |
53,254 | protected function memoryExceeded ( ) { static $ warning_percent = 0.5 ; $ percent = ( memory_get_usage ( ) / 1024 / 1024 ) / $ this -> memoryLimit ; if ( $ percent >= $ warning_percent ) { $ this -> log ( sprintf ( 'Memory usage at %d%% (Max %s MB)' , round ( $ percent * 100 , 1 ) , $ this -> memoryLimit ) , Logger ::... | Determine if the memory limit has been exceeded . |
53,255 | public static function get ( $ stat , $ key = Stats :: DEFAULT_KEY ) { return ( int ) Redis :: instance ( ) -> hget ( $ key , $ stat ) ; } | Get the value of the supplied statistic counter for the specified statistic |
53,256 | public static function clear ( $ stat , $ key = Stats :: DEFAULT_KEY ) { return ( bool ) Redis :: instance ( ) -> hdel ( $ key , $ stat ) ; } | Delete a statistic with the given name . |
53,257 | public function processor ( Command $ command , InputInterface $ input , OutputInterface $ output , array $ args ) { return new StripFormatProcessor ( $ command , $ input , $ output ) ; } | The default processor is the StripFormatProcessor which removes all the console colour formatting from the string |
53,258 | public static function redisKey ( $ queue = null , $ suffix = null ) { if ( is_null ( $ queue ) ) { return 'queues' ; } return ( strpos ( $ queue , 'queue:' ) !== 0 ? 'queue:' : '' ) . $ queue . ( $ suffix ? ':' . $ suffix : '' ) ; } | Get the Queue key |
53,259 | public function push ( $ job , array $ data = null , $ queue = null ) { if ( false !== ( $ delay = \ Resque :: getConfig ( 'default.jobs.delay' , false ) ) ) { return $ this -> later ( $ delay , $ job , $ data , $ queue ) ; } return Job :: create ( $ this -> getQueue ( $ queue ) , $ job , $ data ) ; } | Push a new job onto the queue |
53,260 | protected function getCodeFromFile ( ) { $ file = $ this -> getFile ( ) ; $ code = '' ; while ( $ file -> key ( ) < $ this -> reflection -> getEndLine ( ) ) { $ code .= $ file -> current ( ) ; $ file -> next ( ) ; } preg_match ( '/function\s*\(/' , $ code , $ matches , PREG_OFFSET_CAPTURE ) ; $ begin = isset ( $ matche... | Extract the code from the Closure s file . |
53,261 | protected function getFile ( ) { $ file = new SplFileObject ( $ this -> reflection -> getFileName ( ) ) ; $ file -> seek ( $ this -> reflection -> getStartLine ( ) - 1 ) ; return $ file ; } | Get an SplObjectFile object at the starting line of the Closure . |
53,262 | public function getVariables ( ) { if ( ! $ this -> getUseIndex ( ) ) { return array ( ) ; } $ staticVariables = $ this -> reflection -> getStaticVariables ( ) ; $ usedVariables = array ( ) ; foreach ( $ this -> getUseClauseVariables ( ) as $ variable ) { $ variable = trim ( $ variable , ' $&' ) ; $ usedVariables [ $ v... | Get the variables used by the Closure . |
53,263 | protected function getUseClauseVariables ( ) { $ begin = strpos ( $ code = $ this -> getCode ( ) , '(' , $ this -> getUseIndex ( ) ) + 1 ; return explode ( ',' , substr ( $ code , $ begin , strpos ( $ code , ')' , $ begin ) - $ begin ) ) ; } | Get the variables from the use clause . |
53,264 | public function unserialize ( $ serialized ) { $ payload = unserialize ( $ serialized ) ; extract ( $ payload [ 'variables' ] ) ; eval ( '$this->closure = ' . $ payload [ 'code' ] . ';' ) ; $ this -> reflection = new ReflectionFunction ( $ this -> closure ) ; } | Unserialize the Closure instance . |
53,265 | public function start ( ) { if ( false === ( $ this -> socket = @ socket_create ( AF_INET , SOCK_STREAM , getprotobyname ( $ this -> config [ 'protocol' ] ) ) ) ) { throw new Exception ( sprintf ( 'socket_create(AF_INET, SOCK_STREAM, <%s>) failed: [%d] %s' , $ this -> config [ 'protocol' ] , $ code = socket_last_error ... | Starts the server |
53,266 | public function close ( ) { foreach ( $ this -> clients as & $ client ) { $ this -> disconnect ( $ client , 'Receiver shutting down... Goodbye.' ) ; } socket_close ( $ this -> socket ) ; } | Closes the socket on shutdown |
53,267 | public function disconnect ( Client $ client , $ message = 'Goodbye.' ) { $ this -> fire ( self :: CLIENT_DISCONNECT , $ client , $ message ) ; $ this -> log ( 'Client disconnected: <pop>' . $ client . '</pop>' , Logger :: INFO ) ; $ client -> disconnect ( ) ; $ i = array_search ( $ client , $ this -> clients ) ; unset... | Disconnect a client |
53,268 | public static function fwrite ( $ fh , $ string ) { for ( $ written = 0 ; $ written < strlen ( $ string ) ; $ written += $ fwrite ) { if ( ( $ fwrite = fwrite ( $ fh , substr ( $ string , $ written ) ) ) === false ) { return $ written ; } } return $ written ; } | Write a string to a resource |
53,269 | public function resolve ( $ logFormat ) { foreach ( $ this -> connectionMap as $ connection => $ match ) { if ( $ connection == 'Stream' and stripos ( $ logFormat , 'stream' ) !== 0 ) { $ pattern = '~^(?P<handler>' . implode ( '|' , array_keys ( $ this -> connectionMap ) ) . ')(.*)$~i' ; if ( $ possible = $ this -> mat... | Resolves a Monolog handler from string input |
53,270 | private function matches ( $ pattern , $ subject ) { if ( preg_match ( $ pattern , $ subject , $ matches ) ) { $ args = array ( ) ; foreach ( $ matches as $ key => $ value ) { if ( ! is_int ( $ key ) ) { $ args [ $ key ] = $ value ; } } return $ args ; } return false ; } | Performs a pattern match on a string and returns just the named matches or false if no match |
53,271 | public function addNamespace ( $ string ) { if ( is_array ( $ string ) ) { foreach ( $ string as & $ str ) { $ str = $ this -> addNamespace ( $ str ) ; } return $ string ; } if ( strpos ( $ string , $ this -> namespace ) !== 0 ) { $ string = $ this -> namespace . $ string ; } return $ string ; } | Add Redis namespace to a string |
53,272 | public function removeNamespace ( $ string ) { $ prefix = $ this -> namespace ; if ( substr ( $ string , 0 , strlen ( $ prefix ) ) == $ prefix ) { $ string = substr ( $ string , strlen ( $ prefix ) , strlen ( $ string ) ) ; } return $ string ; } | Remove Redis namespace from string |
53,273 | public static function eventName ( $ event ) { static $ constants = null ; if ( is_null ( $ constants ) ) { $ class = new \ ReflectionClass ( 'Resque\Event' ) ; $ constants = array ( ) ; foreach ( $ class -> getConstants ( ) as $ name => $ value ) { $ constants [ $ value ] = strtolower ( $ name ) ; } } return isset ( $... | Returns the name of the given event from constant |
53,274 | public function registerEvents ( ) { $ job = & $ this -> job ; Event :: listen ( Event :: JOB_PERFORM , function ( $ event , $ _job ) use ( & $ job ) { $ job = $ _job ; } ) ; } | which outputs all the debugging logs |
53,275 | public function log ( $ message , $ context = null , $ logType = null ) { if ( is_int ( $ context ) and is_null ( $ logType ) ) { $ logType = $ context ; $ context = array ( ) ; } if ( ! is_array ( $ context ) ) { $ context = is_null ( $ context ) ? array ( ) : array ( $ context ) ; } if ( ! is_int ( $ logType ) ) { $ ... | Send log message to output interface |
53,276 | public static function loadConfig ( $ file = self :: DEFAULT_CONFIG_FILE ) { self :: readConfigFile ( $ file ) ; Redis :: setConfig ( array ( 'scheme' => static :: getConfig ( 'redis.scheme' , Redis :: DEFAULT_SCHEME ) , 'host' => static :: getConfig ( 'redis.host' , Redis :: DEFAULT_HOST ) , 'port' => static :: getCon... | Reads and loads data from a config file |
53,277 | public static function readConfigFile ( $ file = self :: DEFAULT_CONFIG_FILE ) { if ( ! is_string ( $ file ) ) { throw new InvalidArgumentException ( 'The config file path must be a string, type passed "' . gettype ( $ file ) . '".' ) ; } $ baseDir = realpath ( dirname ( $ file ) ) ; $ searchDirs = array ( $ baseDir . ... | Reads data from a config file |
53,278 | public static function getConfig ( $ key = null , $ default = null ) { if ( ! is_null ( $ key ) ) { if ( false !== Util :: path ( static :: $ config , $ key , $ found ) ) { return $ found ; } else { return $ default ; } } return static :: $ config ; } | Gets Resque config variable |
53,279 | public function working ( Worker $ worker ) { $ this -> redis -> sadd ( self :: redisKey ( ) , $ this -> hostname ) ; $ this -> redis -> sadd ( self :: redisKey ( $ this ) , ( string ) $ worker ) ; $ this -> redis -> expire ( self :: redisKey ( $ this ) , $ this -> timeout ) ; } | Mark host as having an active worker |
53,280 | public function finished ( Worker $ worker ) { $ this -> redis -> srem ( self :: redisKey ( $ this ) , ( string ) $ worker ) ; } | Mark host as having a finished worker |
53,281 | public function cleanup ( ) { $ hosts = $ this -> redis -> smembers ( self :: redisKey ( ) ) ; $ workers = $ this -> redis -> smembers ( Worker :: redisKey ( ) ) ; $ cleaned = array ( 'hosts' => array ( ) , 'workers' => array ( ) ) ; foreach ( $ hosts as $ hostname ) { $ host = new static ( $ hostname ) ; if ( ! $ this... | Cleans up any dead hosts |
53,282 | protected function mergeDefinitions ( array $ definitions ) { return array_merge ( $ definitions , array ( new InputOption ( 'config' , 'c' , InputOption :: VALUE_OPTIONAL , 'Path to config file. Inline options override.' , Resque :: DEFAULT_CONFIG_FILE ) , new InputOption ( 'include' , 'I' , InputOption :: VALUE_OPTIO... | Globally sets some input options that are available for all commands |
53,283 | protected function parseConfig ( $ config , $ defaults ) { if ( array_key_exists ( 'config' , $ config ) ) { $ configFileData = Resque :: readConfigFile ( $ config [ 'config' ] ) ; foreach ( $ config as $ key => & $ value ) { if ( isset ( $ this -> configOptionMap [ $ key ] ) and ( ( $ key === 'verbose' or $ value === ... | Parses the configuration file |
53,284 | protected function getConfig ( $ key = null ) { if ( ! is_null ( $ key ) ) { if ( ! array_key_exists ( $ key , $ this -> config ) ) { throw new \ InvalidArgumentException ( 'Config key "' . $ key . '" does not exist. Valid keys are: "' . implode ( ', ' , array_keys ( $ this -> config ) ) . '"' ) ; } return $ this -> co... | Returns all config items or a specific one |
53,285 | public static function human_time_diff ( $ from , $ to = null ) { $ to = $ to ? : time ( ) ; $ diff = ( int ) abs ( $ to - $ from ) ; if ( $ diff < self :: MINUTE_IN_SECONDS ) { $ since = array ( $ diff , 'sec' ) ; } elseif ( $ diff < self :: HOUR_IN_SECONDS ) { $ since = array ( round ( $ diff / self :: MINUTE_IN_SECO... | Determines the difference between two timestamps . |
53,286 | public static function path ( $ array , $ path , & $ found , $ delimiter = '.' ) { if ( ! is_array ( $ array ) ) { return false ; } if ( is_array ( $ path ) ) { $ keys = $ path ; } else { if ( array_key_exists ( $ path , $ array ) ) { $ found = $ array [ $ path ] ; return true ; } $ keys = explode ( $ delimiter , trim ... | Gets a value from an array using a dot separated path . Returns true if found and false if not . |
53,287 | public function setMaxCount ( int $ maxCount ) : StreamMetadataBuilder { if ( $ maxCount < 0 ) { throw new InvalidArgumentException ( 'Max count must be positive' ) ; } $ this -> maxCount = $ maxCount ; return $ this ; } | Sets the maximum number of events allowed in the stream |
53,288 | public function setCacheControl ( int $ cacheControl ) : StreamMetadataBuilder { if ( $ cacheControl < 0 ) { throw new InvalidArgumentException ( 'CacheControl must be positive' ) ; } $ this -> cacheControl = $ cacheControl ; return $ this ; } | Sets the amount of time for which the stream head is cachable |
53,289 | public function clear ( $ keys = null ) { if ( is_null ( $ keys ) ) { $ this -> items = [ ] ; return ; } $ keys = ( array ) $ keys ; foreach ( $ keys as $ key ) { $ this -> set ( $ key , [ ] ) ; } } | Delete the contents of a given key or keys |
53,290 | public function delete ( $ keys ) { $ keys = ( array ) $ keys ; foreach ( $ keys as $ key ) { if ( $ this -> exists ( $ this -> items , $ key ) ) { unset ( $ this -> items [ $ key ] ) ; continue ; } $ items = & $ this -> items ; $ segments = explode ( '.' , $ key ) ; $ lastSegment = array_pop ( $ segments ) ; foreach (... | Delete the given key or keys |
53,291 | public function flatten ( $ delimiter = '.' , $ items = null , $ prepend = '' ) { $ flatten = [ ] ; if ( is_null ( $ items ) ) { $ items = $ this -> items ; } foreach ( $ items as $ key => $ value ) { if ( is_array ( $ value ) && ! empty ( $ value ) ) { $ flatten = array_merge ( $ flatten , $ this -> flatten ( $ delimi... | Flatten an array with the given character as a key delimiter |
53,292 | protected function getArrayItems ( $ items ) { if ( is_array ( $ items ) ) { return $ items ; } elseif ( $ items instanceof self ) { return $ items -> all ( ) ; } return ( array ) $ items ; } | Return the given items as an array |
53,293 | public function pull ( $ key = null , $ default = null ) { if ( is_null ( $ key ) ) { $ value = $ this -> all ( ) ; $ this -> clear ( ) ; return $ value ; } $ value = $ this -> get ( $ key , $ default ) ; $ this -> delete ( $ key ) ; return $ value ; } | Return the value of a given key and delete the key |
53,294 | public function push ( $ key , $ value = null ) { if ( is_null ( $ value ) ) { $ this -> items [ ] = $ key ; return ; } $ items = $ this -> get ( $ key ) ; if ( is_array ( $ items ) || is_null ( $ items ) ) { $ items [ ] = $ value ; $ this -> set ( $ key , $ items ) ; } } | Push a given value to the end of the array in a given key |
53,295 | public function replace ( $ key , $ value = [ ] ) { if ( is_array ( $ key ) ) { $ this -> items = array_replace ( $ this -> items , $ key ) ; } elseif ( is_string ( $ key ) ) { $ items = ( array ) $ this -> get ( $ key ) ; $ value = array_replace ( $ items , $ this -> getArrayItems ( $ value ) ) ; $ this -> set ( $ key... | Replace all values or values within the given key with an array or Dot object |
53,296 | private static function castValue ( $ val , $ trim = false ) { if ( is_array ( $ val ) ) { foreach ( $ val as $ key => $ value ) { $ val [ $ key ] = self :: castValue ( $ value ) ; } } elseif ( is_string ( $ val ) ) { if ( $ trim ) { $ val = trim ( $ val ) ; } $ val = stripslashes ( $ val ) ; $ tmp = strtolower ( $ val... | Try determinate the original type variable of a string |
53,297 | public function parse ( $ template_file ) { if ( file_exists ( $ template_file ) ) { $ content = file_get_contents ( $ template_file ) ; foreach ( $ this -> vars as $ key => $ value ) { if ( is_array ( $ value ) ) { $ content = $ this -> parsePair ( $ key , $ value , $ content ) ; } else { $ content = $ this -> parseSi... | Parse template file |
53,298 | private function parseSingle ( $ key , $ value , $ string , $ index = null ) { if ( isset ( $ index ) ) { $ string = str_replace ( $ this -> l_delim . '%index%' . $ this -> r_delim , $ index , $ string ) ; } return str_replace ( $ this -> l_delim . $ key . $ this -> r_delim , $ value , $ string ) ; } | Parsing content for single varliable |
53,299 | private function parsePair ( $ variable , $ data , $ string ) { $ match = $ this -> matchPair ( $ string , $ variable ) ; if ( $ match == false ) return $ string ; $ str = '' ; foreach ( $ data as $ k_row => $ row ) { $ temp = $ match [ '1' ] ; foreach ( $ row as $ key => $ val ) { if ( ! is_array ( $ val ) ) { $ index... | Parsing content for loop varliable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.