-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample-6.php
44 lines (37 loc) · 991 Bytes
/
sample-6.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
if (! extension_loaded('pthreads')) {
echo "!! Need the pthreads extension !!" . PHP_EOL;
exit(1);
}
require_once __DIR__ . '/../vendor/autoload.php';
use PHPFluent\EventManager\Manager;
use PHPFluent\EventManager\Listener\PThread;
/**
* Personalized Thread class
* @see http://php.net/pthreads
* @see http://php.net/class.thread
*/
class MyThread extends \Thread
{
/**
* the script process to run in background
*/
public function run()
{
echo "-thread.start: " . date('H:i:s') . PHP_EOL;
sleep(5);
echo "-thread...end: " . date('H:i:s') . PHP_EOL;
}
}
// create the listener
$listener = new PThread(
new MyThread() // with MyThread
);
$manager = new Manager();
$manager->addEventListener('thread', $listener);
// dispatch listener in background.
$manager->dispatchEvent('thread');
//continue executing
echo '* Script Execution Continued...' . PHP_EOL;
//sleep(2);
echo '* Script Execution Finished!' . PHP_EOL;