Last active
September 23, 2016 08:38
-
-
Save zonuexe/7fa3af65564e235be06c1593a67fd225 to your computer and use it in GitHub Desktop.
ticksを使ってみたサンプル
This file contains hidden or 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 | |
var_dump(PHP_SAPI); | |
pcntl_signal(SIGALRM, function () { | |
var_dump("おしまい", time()); exit; | |
}); | |
// 2秒後にセット | |
pcntl_alarm(2); | |
$i = 0; | |
while (true) { | |
var_dump(++$i); | |
usleep(200000); | |
} |
This file contains hidden or 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=1000); | |
$begin = microtime(true); | |
register_tick_function(function () use ($begin) { | |
static $time = 0; | |
$now = microtime(true); | |
var_dump($time++, $now - $begin); | |
if ($now - $begin > 0.5) { | |
var_dump("0.5秒経ったよ…"); | |
exit; | |
} | |
}); | |
while (true) { | |
// 無限ループって怖くね? | |
usleep(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment