PHP Class WP_Background_Process, wp-background-processing

Inheritance: extends WP_Async_Request
显示文件 Open project: A5hleyRich/wp-background-processing Class Usage Examples

Protected Properties

Property Type Description
$action string (default value: 'background_process')
$cron_hook_identifier mixed Cron_hook_identifier
$cron_interval_identifier mixed Cron_interval_identifier
$start_time integer (default value: 0)

Public Methods

Method Description
__construct ( ) Initiate new background process
cancel_process ( ) Cancel Process
delete ( string $key ) Delete queue
dispatch ( ) : void Dispatch
handle_cron_healthcheck ( ) Handle cron healthcheck
maybe_handle ( ) Maybe process queue
push_to_queue ( mixed $data ) Push to queue
save ( ) Save queue
schedule_cron_healthcheck ( mixed $schedules ) : mixed Schedule cron healthcheck
update ( string $key, array $data ) Update queue

Protected Methods

Method Description
clear_scheduled_event ( ) Clear scheduled event
complete ( ) Complete.
generate_key ( integer $length = 64 ) : string Generate key
get_batch ( ) : stdClass Get batch
get_memory_limit ( ) : integer Get memory limit
handle ( ) Handle
is_process_running ( ) Is process running
is_queue_empty ( ) : boolean Is queue empty
lock_process ( ) Lock process
memory_exceeded ( ) : boolean Memory exceeded
schedule_event ( ) Schedule event
task ( mixed $item ) : mixed Task
time_exceeded ( ) : boolean Time exceeded.
unlock_process ( ) Unlock process

Method Details

__construct() public method

Initiate new background process
public __construct ( )

cancel_process() public method

Stop processing queue items, clear cronjob and delete batch.
public cancel_process ( )

clear_scheduled_event() protected method

Clear scheduled event
protected clear_scheduled_event ( )

complete() protected method

Override if applicable, but ensure that the below actions are performed, or, call parent::complete().
protected complete ( )

delete() public method

Delete queue
public delete ( string $key )
$key string Key.

dispatch() public method

Dispatch
public dispatch ( ) : void
return void

generate_key() protected method

Generates a unique key based on microtime. Queue items are given a unique key so that they can be merged upon save.
protected generate_key ( integer $length = 64 ) : string
$length integer Length.
return string

get_batch() protected method

Get batch
protected get_batch ( ) : stdClass
return stdClass Return the first batch from the queue

get_memory_limit() protected method

Get memory limit
protected get_memory_limit ( ) : integer
return integer

handle() protected method

Pass each queue item to the task handler, while remaining within server memory and time limit constraints.
protected handle ( )

handle_cron_healthcheck() public method

Restart the background process if not already running and data exists in the queue.

is_process_running() protected method

Check whether the current process is already running in a background process.
protected is_process_running ( )

is_queue_empty() protected method

Is queue empty
protected is_queue_empty ( ) : boolean
return boolean

lock_process() protected method

Lock the process so that multiple instances can't run simultaneously. Override if applicable, but the duration should be greater than that defined in the time_exceeded() method.
protected lock_process ( )

maybe_handle() public method

Checks whether data exists within the queue and that the process is not already running.
public maybe_handle ( )

memory_exceeded() protected method

Ensures the batch process never exceeds 90% of the maximum WordPress memory.
protected memory_exceeded ( ) : boolean
return boolean

push_to_queue() public method

Push to queue
public push_to_queue ( mixed $data )
$data mixed Data.

save() public method

Save queue
public save ( )

schedule_cron_healthcheck() public method

Schedule cron healthcheck
public schedule_cron_healthcheck ( mixed $schedules ) : mixed
$schedules mixed Schedules.
return mixed

schedule_event() protected method

Schedule event
protected schedule_event ( )

task() abstract protected method

Override this method to perform any actions required on each queue item. Return the modified item for further processing in the next pass through. Or, return false to remove the item from the queue.
abstract protected task ( mixed $item ) : mixed
$item mixed Queue item to iterate over.
return mixed

time_exceeded() protected method

Ensures the batch never exceeds a sensible time limit. A timeout limit of 30s is common on shared hosting.
protected time_exceeded ( ) : boolean
return boolean

unlock_process() protected method

Unlock the process so that other instances can spawn.
protected unlock_process ( )

update() public method

Update queue
public update ( string $key, array $data )
$key string Key.
$data array Data.

Property Details

$action protected_oe property

(default value: 'background_process')
protected string $action
return string

$cron_hook_identifier protected_oe property

Cron_hook_identifier
protected mixed $cron_hook_identifier
return mixed

$cron_interval_identifier protected_oe property

Cron_interval_identifier
protected mixed $cron_interval_identifier
return mixed

$start_time protected_oe property

(default value: 0)
protected int $start_time
return integer