\seekquarry\yioop\libraryCrawlDaemon

Used to run scripts as a daemon on *nix systems

Summary

Methods
Properties
Constants
processHandler()
init()
daemonLog()
start()
execInOwnProcess()
stop()
getMesssageFileName()
getLockFileName()
getNameString()
statuses()
$name
$subname
$mode
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$name

$name : string

Name prefix to be used on files associated with this daemon (such as lock like and messages)

Type

string

$subname

$subname : string

Subname of the name prefix used on files associated with this daemon For example, the name might be fetcher, the subname might 2 to indicate which fetcher daemon instance.

Type

string

$mode

$mode : string

Used by processHandler to decide whether run as daemon or not

Type

string

Methods

processHandler()

processHandler(boolean  $continue = false) 

Tick callback function used to update the timestamp in this processes lock. If lock_file does not exist or more than PROCESS_TIMEOUT time has elapsed since the last processHandler call it stops the process

Parameters

boolean $continue

if true only stop if lock file not present, ignore PROCESS_TIMEOUT time being exceeded.

init()

init(array  $init_argv, string  $name, integer  $exit_type = 1, string  $use_message = "") 

Used to send a message the given daemon or run the program in the foreground.

Parameters

array $init_argv

an array of command line arguments. The argument start will check if the process control functions exists if these do they will fork and detach a child process to act as a daemon. a lock file will be created to prevent additional daemons from running. If the message is stop then a message file is written to tell the daemon to stop. If the argument is terminal then the program won't be run as a daemon.

string $name

the prefix to use for lock and message files

integer $exit_type

whether this function should exit > 0 or return (1) by default a lock file is only written if exit (this allows both queue server processes (Indexer and Scheduler) to use the same lock file. If exit is >=3 or <= -3 then doesn't check lock to see if already running before starting

string $use_message

echo'd if incorrect parameters sent

daemonLog()

daemonLog(string  $msg, integer  $exit_type) 

Used to print a log message in a way helpful to aid debugging CrawlDaemon tasks where crawlLog() might not yet be set up Sends the message to stardard out if crawlLog not set up; otherwise, sends to crawlLog()

Parameters

string $msg

string to log to either standard out or to Yioop's crawlLog

integer $exit_type

the exit_type used by init() and start() values of absolute value >2 are only used if crawlLog has already been set up

start()

start(string  $name, string  $subname = "", string  $options = "", integer  $exit = 1) 

Used to start a daemon running in the background

Parameters

string $name

the main name of this daemon such as queue_server or fetcher.

string $subname

the instance name if it is possible for more than one copy of the daemon to be running at the same time

string $options

a string of additional command line options

integer $exit

whether this function should exit > 0 or return (1) by default a lock file is only written if exit (this allows both queue server processes (Indexer and Scheduler) to use the same lock file. If exit is >=3 or <= -3 then doesn't check lock to see if already running before starting

execInOwnProcess()

execInOwnProcess(string  $cmd) 

Used to execute a shell command in its own process

Parameters

string $cmd

the command to execute

stop()

stop(string  $name, string  $subname = "", boolean  $exit = true) 

Used to stop a daemon that is running in the background

Parameters

string $name

the main name of this daemon such as QueueServer or Fetcher.

string $subname

the instance name if it is possible for more than one copy of the daemon to be running at the same time

boolean $exit

whether this method should just return (false) or call exit() (true)

getMesssageFileName()

getMesssageFileName(string  $name, string  $subname = "") : string

Used to return the string name of the messages file used to pass messages to a daemon running in the background

Parameters

string $name

the main name of this daemon such as queue_server or fetcher.

string $subname

the instance name if it is possible for more than one copy of the daemon to be running at the same time

Returns

string —

the name of the message file for the daemon with the given name and subname

getLockFileName()

getLockFileName(string  $name, string  $subname = "") : string

Used to return the string name of the lock file used to pass by a daemon

Parameters

string $name

the main name of this daemon such as queue_server or fetcher.

string $subname

the instance name if it is possible for more than one copy of the daemon to be running at the same time

Returns

string —

the name of the lock file for the daemon with the given name and subname

getNameString()

getNameString(string  $name, string  $subname) : string

Used to return a string name for a given daemon instance

Parameters

string $name

the main name of this daemon such as queue_server or fetcher.

string $subname

the instance name if it is possible for more than one copy of the daemon to be running at the same time

Returns

string —

a single name that combines the name and subname

statuses()

statuses() : array

Returns the statuses of the running daemons

Returns

array —

2d array active_daemons[name][instance] = true