flush
[m6w6/atick] / README.md
1 atick
2 =====
3 [![Build Status](https://travis-ci.org/mike-php-net/atick.png?branch=master)](https://travis-ci.org/mike-php-net/atick)
4
5 Asynchronnous resource handling, optionally (ab)using ticks.
6
7 **Example with ticks:**
8
9 ```PHP
10 declare(ticks=1);
11
12 $conn = new \pq\Connection;
13 $conn->execAsync("SELECT * FROM foo", function ($rs) {
14 var_dump($rs);
15 });
16
17 $ticker = new \atick\Ticker;
18 $ticker->register();
19 $ticker->read($conn->socket, function($fd) use ($conn) {
20 $conn->poll();
21 if ($conn->busy) {
22 return false;
23 }
24 $conn->getResult();
25 return true;
26 });
27
28 while (count($ticker));
29 ```
30
31 **And an example without ticks:**
32
33 ```php
34 $conn = new \pq\Connection;
35 $conn->execAsync("SELECT * FROM foo", function ($r) {
36 var_dump($r);
37 });
38
39 $ticker = new \atick\Ticker;
40 $ticker->read($conn->socket, function($fd) use ($conn) {
41 $conn->poll();
42 if ($conn->busy) {
43 return false;
44 }
45 $conn->getResult();
46 return true;
47 });
48
49 while($ticker());
50 ```