Exceptions
5 years ago
Job
1 month ago
Action.php
2 years ago
BackgroundProcessingServiceProvider.php
1 month ago
Demo.php
4 years ago
FeatureDetection.php
3 months ago
Queue.php
1 month ago
QueueActionAware.php
6 months ago
QueueProcessor.php
1 month ago
WithQueueAwareness.php
1 month ago
Demo.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Runs a Queue Background Processing Demo from the browser. |
| 5 | * |
| 6 | * Go to https:<site>/?wpstg_q_demo to run the demo queueing 100 actions and close all browser windows on the site. |
| 7 | * |
| 8 | * Go to https:<site>/?wpstg_q_demo=<n> to run the demo queueing <n> actions and close all browser windows on the site. |
| 9 | * |
| 10 | * @since TBD |
| 11 | * |
| 12 | * @package WPStaging\Framework\BackgroundProcessing |
| 13 | */ |
| 14 | |
| 15 | namespace WPStaging\Framework\BackgroundProcessing; |
| 16 | |
| 17 | use WPStaging\Core\WPStaging; |
| 18 | |
| 19 | class Demo |
| 20 | { |
| 21 | public function run($count) |
| 22 | { |
| 23 | $queue = WPStaging::getInstance()->getContainer()->make(Queue::class); |
| 24 | |
| 25 | foreach (range(1, $count) as $k) { |
| 26 | $queue->enqueueAction(self::class . '::' . 'writeToLog', [$k]); |
| 27 | \WPStaging\functions\debug_log("Enqueued Action {$k}"); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | public function writeToLog($k) |
| 32 | { |
| 33 | $interval = mt_rand(0, 2); |
| 34 | sleep($interval); |
| 35 | $pid = getmypid(); |
| 36 | \WPStaging\functions\debug_log("Action {$k} done [PID {$pid}]!"); |
| 37 | } |
| 38 | } |
| 39 |