-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloop_io_stream_source.php
More file actions
49 lines (41 loc) · 1.57 KB
/
loop_io_stream_source.php
File metadata and controls
49 lines (41 loc) · 1.57 KB
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
45
46
47
48
49
<?php
/**
* ---------------------------------------------------------------------------------------------------------------------
* DESCRIPTION
* ---------------------------------------------------------------------------------------------------------------------
* This file contains the example of using streams in loop.
*
* ---------------------------------------------------------------------------------------------------------------------
* USAGE
* ---------------------------------------------------------------------------------------------------------------------
* To run this example in CLI from project root use following syntax
*
* $> php ./example/loop_io_stream_source.php
*
* Following flags are supported to test example with different configurations:
*
* --model : define model to use, default: select, supported: [ select ]
*
* Ex:
* $> php ./example/loop_io_stream_source.php --model=select
*
* IMPORTANT!!!
*
* For the best result, use loop_io_stream_source.php and loop_io_stream_pipe.php together.
*
* Ex:
* $> php ./example/loop_io_stream_source.php | php ./example/loop_io_stream_pipe.php
* ---------------------------------------------------------------------------------------------------------------------
*/
$model = '';
require_once __DIR__ . '/bootstrap/autoload.php';
use Dazzle\Loop\Loop;
$loop = new Loop(new $model);
if (stream_set_blocking(STDOUT, false) !== true) {
fwrite(STDERR, "ERROR: Unable to set STDOUT non-blocking.\n");
exit(1);
}
$loop->addPeriodicTimer(0.25, function() {
printf("NEW LINE\n");
});
$loop->start();