Created
February 1, 2013 17:55
-
-
Save anonymous/4692904 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(ticks=10); | |
// A function called on each tick event | |
class Counter { | |
static $a = 0; | |
static $b = 0; | |
} | |
function tick_handler() | |
{ | |
Counter::$b++; | |
} | |
$stream1 = fopen("http://amazon.com", "r"); | |
$stream2 = fopen("http://news.ycombinator.com", "r"); | |
stream_set_blocking($stream1, 0); | |
stream_set_blocking($stream2, 0); | |
register_tick_function('tick_handler', 1); | |
$read = array($stream1, $stream2); | |
$write = NULL; | |
$except = NULL; | |
while (True){ | |
$line = fgets($stream2); | |
if ($line == "") { | |
Counter::$a++; | |
} else { | |
break; | |
} | |
} | |
echo Counter::$a."\n".Counter::$b."\n"; | |
fclose($stream1); | |
fclose($stream2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment