CrawlDaemon
in package
implements
CrawlConstants
Used to run scripts as a daemon on *nix systems
Tags
Interfaces, Classes, Traits and Enums
- CrawlConstants
- Shared constants and enums used by components that are involved in the crawling process
Table of Contents
- GLOBAL_STOP_FILE_NAME = \seekquarry\yioop\configs\DATA_DIR . "/GlobalStop.txt"
- $mode : string
- Used by processHandler to decide whether run as daemon or not
- $name : string
- Name prefix to be used on files associated with this daemon (such as lock like and messages)
- $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.
- daemonLog() : mixed
- 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 standard out if crawlLog not set up; otherwise, sends to crawlLog()
- execInOwnProcess() : mixed
- Used to execute a shell command in its own process SECURITY WARNING: Do not use with a computable arguments!!
- execScriptInOwnProcess() : mixed
- Used to execute a php script in its own process SECURITY WARNING: Do not use with a computable arguments!!
- getLockFileName() : string
- Used to return the string name of the lock file used to pass by a daemon
- getMessageFileName() : string
- Used to return the string name of the messages file used to pass messages to a daemon running in the background
- getNameString() : string
- Used to return a string name for a given daemon instance
- init() : mixed
- Used to send a message the given daemon or run the program in the foreground.
- processHandler() : mixed
- 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
- start() : mixed
- Used to start a daemon running in the background
- statuses() : array<string|int, mixed>
- Returns the statuses of the running daemons
- stop() : mixed
- Used to stop a daemon that is running in the background
Constants
GLOBAL_STOP_FILE_NAME
public
mixed
GLOBAL_STOP_FILE_NAME
= \seekquarry\yioop\configs\DATA_DIR . "/GlobalStop.txt"
Properties
$mode
Used by processHandler to decide whether run as daemon or not
public
static string
$mode
Tags
$name
Name prefix to be used on files associated with this daemon (such as lock like and messages)
public
static string
$name
Tags
$subname
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.
public
static string
$subname
Tags
Methods
daemonLog()
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 standard out if crawlLog not set up; otherwise, sends to crawlLog()
public
static daemonLog(string $msg, int $exit_type) : mixed
Parameters
- $msg : string
-
string to log to either standard out or to Yioop's crawlLog
- $exit_type : int
-
the exit_type used by init() and start() values of absolute value >2 are only used if crawlLog has already been set up
Return values
mixed —execInOwnProcess()
Used to execute a shell command in its own process SECURITY WARNING: Do not use with a computable arguments!!
public
static execInOwnProcess(string $cmd[, string $output = '/dev/null' ]) : mixed
Parameters
- $cmd : string
-
the command to execute
- $output : string = '/dev/null'
-
where to redirect output to
Return values
mixed —execScriptInOwnProcess()
Used to execute a php script in its own process SECURITY WARNING: Do not use with a computable arguments!!
public
static execScriptInOwnProcess(string $script_name[, string $options = "" ][, string $output = '/dev/null' ]) : mixed
Parameters
- $script_name : string
-
name of a PHP script
- $options : string = ""
-
command line options to send script
- $output : string = '/dev/null'
-
where to redirect output to
Return values
mixed —getLockFileName()
Used to return the string name of the lock file used to pass by a daemon
public
static getLockFileName(string $name[, string $subname = "" ]) : string
Parameters
- $name : string
-
the main name of this daemon such as queue_server or fetcher.
- $subname : string = ""
-
the instance name if it is possible for more than one copy of the daemon to be running at the same time
Return values
string —the name of the lock file for the daemon with the given name and subname
getMessageFileName()
Used to return the string name of the messages file used to pass messages to a daemon running in the background
public
static getMessageFileName(string $name[, string $subname = "" ]) : string
Parameters
- $name : string
-
the main name of this daemon such as queue_server or fetcher.
- $subname : string = ""
-
the instance name if it is possible for more than one copy of the daemon to be running at the same time
Return values
string —the name of the message file for the daemon with the given name and subname
getNameString()
Used to return a string name for a given daemon instance
public
static getNameString(string $name, string $subname) : string
Parameters
- $name : string
-
the main name of this daemon such as queue_server or fetcher.
- $subname : string
-
the instance name if it is possible for more than one copy of the daemon to be running at the same time
Return values
string —a single name that combines the name and subname
init()
Used to send a message the given daemon or run the program in the foreground.
public
static init(array<string|int, mixed> $init_argv, string $name[, int $exit_type = 1 ][, string $use_message = "" ]) : mixed
Parameters
- $init_argv : array<string|int, mixed>
-
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.
- $name : string
-
the prefix to use for lock and message files
- $exit_type : int = 1
-
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
- $use_message : string = ""
-
echo'd if incorrect parameters sent
Return values
mixed —processHandler()
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
public
static processHandler([bool $continue = false ]) : mixed
Parameters
- $continue : bool = false
-
if true only stop if lock file not present, ignore PROCESS_TIMEOUT time being exceeded.
Return values
mixed —start()
Used to start a daemon running in the background
public
static start(string $name[, string $subname = "" ][, string $options = "" ][, int $exit = 1 ]) : mixed
Parameters
- $name : string
-
the main name of this daemon such as queue_server or fetcher.
- $subname : string = ""
-
the instance name if it is possible for more than one copy of the daemon to be running at the same time
- $options : string = ""
-
a string of additional command line options
- $exit : int = 1
-
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
Return values
mixed —statuses()
Returns the statuses of the running daemons
public
static statuses() : array<string|int, mixed>
Return values
array<string|int, mixed> —2d array active_daemons[name][instance] = true
stop()
Used to stop a daemon that is running in the background
public
static stop(string $name[, string $subname = "" ][, bool $exit = true ]) : mixed
Parameters
- $name : string
-
the main name of this daemon such as QueueServer or Fetcher.
- $subname : string = ""
-
the instance name if it is possible for more than one copy of the daemon to be running at the same time
- $exit : bool = true
-
whether this method should just return (false) or call exit() (true)