PHP Class WP_Background_Process, wp-background-processing

Inheritance: extends WP_Async_Request
Afficher le fichier Open project: A5hleyRich/wp-background-processing Class Usage Examples

Protected Properties

Свойство 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)

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

Initiate new background process
public __construct ( )

cancel_process() public méthode

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

clear_scheduled_event() protected méthode

Clear scheduled event
protected clear_scheduled_event ( )

complete() protected méthode

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

delete() public méthode

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

dispatch() public méthode

Dispatch
public dispatch ( ) : void
Résultat void

generate_key() protected méthode

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.
Résultat string

get_batch() protected méthode

Get batch
protected get_batch ( ) : stdClass
Résultat stdClass Return the first batch from the queue

get_memory_limit() protected méthode

Get memory limit
protected get_memory_limit ( ) : integer
Résultat integer

handle() protected méthode

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

handle_cron_healthcheck() public méthode

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

is_process_running() protected méthode

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

is_queue_empty() protected méthode

Is queue empty
protected is_queue_empty ( ) : boolean
Résultat boolean

lock_process() protected méthode

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 méthode

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

memory_exceeded() protected méthode

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

push_to_queue() public méthode

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

save() public méthode

Save queue
public save ( )

schedule_cron_healthcheck() public méthode

Schedule cron healthcheck
public schedule_cron_healthcheck ( mixed $schedules ) : mixed
$schedules mixed Schedules.
Résultat mixed

schedule_event() protected méthode

Schedule event
protected schedule_event ( )

task() abstract protected méthode

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.
Résultat mixed

time_exceeded() protected méthode

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

unlock_process() protected méthode

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

update() public méthode

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
Résultat string

$cron_hook_identifier protected_oe property

Cron_hook_identifier
protected mixed $cron_hook_identifier
Résultat mixed

$cron_interval_identifier protected_oe property

Cron_interval_identifier
protected mixed $cron_interval_identifier
Résultat mixed

$start_time protected_oe property

(default value: 0)
protected int $start_time
Résultat integer