Skip to content

Instantly share code, notes, and snippets.

@zonuexe
Last active September 23, 2016 08:38
Show Gist options
  • Save zonuexe/7fa3af65564e235be06c1593a67fd225 to your computer and use it in GitHub Desktop.
Save zonuexe/7fa3af65564e235be06c1593a67fd225 to your computer and use it in GitHub Desktop.
ticksを使ってみたサンプル
<?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);
}
<?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