PHP code example of devgeniem / wp-queue
1. Go to this page and download the library: Download devgeniem/wp-queue library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
devgeniem / wp-queue example snippets
add_action( 'wpq_add_queue', function( \Psr\Container\ContainerInterface $container ) {
$my_queue = new Geniem\Queue\Instance\RedisQueue( 'my_queue' );
// ...
$container->add( $my_queue );
}, 1, 1 );
$my_queue = wpq()->get_queue_container()->get( 'my_queue' );
class MyHandler implements \Geniem\Queue\Interfaces\EntryHandlerInterface {
public function handle( \Geniem\Queue\Interfaces\EntryInterface $entry ) {
error_log( 'Entry data: ' . $entry->get_data() );
}
}
add_action( 'wpq_add_queue', function( \Psr\Container\ContainerInterface $container ) {
$my_queue = new Geniem\Queue\Instance\RedisQueue( 'my_queue' );
// Set the handler.
$my_queue->set_entry_handler( new Myhandler() );
$container->add( $my_queue );
}, 1, 1 );
class MyFetcher implements \Geniem\Queue\Interfaces\EntryFetcherInterface {
public function fetch() : ?array {
$entry_data = [
'Item 1',
'Item 2',
'Item 3',
'Item 4',
];
return $entries;
}
}
add_action( 'wpq_add_queue', function( \Psr\Container\ContainerInterface $container ) {
$my_queue = new Geniem\Queue\Instance\RedisQueue( 'my_queue' );
// Set the fetcher.
$my_queue->set_entry_fetcher( new MyFetcher() );
$container->add( $my_queue );
}, 1, 1 );
class MyFetcher implements \Geniem\Queue\Interfaces\EntryFetcherInterface {
public function fetch() : ?array {
$entry_data = [
'Item 1',
'Item 2',
'Item 3',
'Item 4',
];
$entries = array_map( function( $data ) {
$entry = new \Geniem\Queue\Entry();
$entry->set_data( $data );
return $entry;
}, $entry_data );
return $entries;
}
}
class MyHandler implements \Geniem\Queue\Interfaces\EntryHandlerInterface {
public function handle( \Geniem\Queue\Interfaces\EntryInterface $entry ) {
error_log( 'Entry data: ' . $entry->get_data() );
}
}
add_action( 'wpq_add_queue', function( \Psr\Container\ContainerInterface $container ) {
$redis_queue = new Geniem\Queue\Instance\RedisQueue( 'my_queue' );
$redis_queue->set_entry_fetcher( new MyFetcher() );
$redis_queue->set_entry_handler( new MyHandler() );
$container->add( $redis_queue );
}, 1, 1 );
$enqueuer = new \Geniem\Queue\Enqueuer();
$enqueuer->fetch( $my_queue );
$dequeuer = new \Geniem\Queue\Dequeuer();
$dequeuer->dequeue( $my_queue );