PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.22
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.22
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / team-updraft / common-libs / src / updraft-semaphore / test.php

test.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.22, at vendor/team-updraft/common-libs/src/updraft-semaphore/test.php

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Example usage:
5
6 php -a
7 require 'wp-load.php';
8 define('I_AM_TESTING', true);
9 require 'test.php';
10 */
11
12 if (!defined('ABSPATH')) die('No direct access.');
13
14 if (!defined('I_AM_TESTING') || !I_AM_TESTING) die('Please define I_AM_TESTING.');
15
16 require_once(dirname(__FILE__).'/class-updraft-semaphore.php');
17
18 class Test_Logger_1 {
19 function log($message, $level) {
20 echo "Test_Logger_1::log(level=$level, message=$message)\n";
21 }
22 }
23
24 class Test_Logger_2 {
25 function log($message, $level) {
26 echo "Test_Logger_2::log(level=$level, message=$message)\n";
27 }
28 }
29
30 $my_lock = new Updraft_Semaphore_3_0('my_test_lock_name', 4, array(new Test_Logger_1()));
31
32 if ($my_lock->lock()) {
33 try {
34 // do stuff ...
35 $my_lock_again = new Updraft_Semaphore_3_0('my_test_lock_name', 4, array(new Test_Logger_2()));
36 $time_now = microtime(true);
37 if ($my_lock_again->lock(6)) {
38 echo "Eventually got it after ".round(microtime(true) - $time_now, 3)." seconds\n";
39 $my_lock_again->release();
40 } else {
41 echo("Sorry, could not get the second lock\n");
42 }
43
44 } catch (Exception $e) {
45 var_dump($e);
46 // We are making sure we release the lock in case of an error
47 } catch (Error $e) { // phpcs:ignore PHPCompatibility.Classes.NewClasses.errorFound
48 var_dump($e);
49 // We are making sure we release the lock in case of an error
50 }
51
52 $my_lock->release();
53
54 } else {
55 echo("Sorry, could not get the first lock\n");
56 }
57