Created
January 22, 2020 19:28
-
-
Save kelunik/a3646bea6c7bee4e2de83d7cd7ea0147 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 | |
use Amp\Loop\Internal\TimerQueue; | |
use Amp\Loop\Watcher; | |
require __DIR__ . '/vendor/autoload.php'; | |
$input = \file_get_contents('/home/kelunik/Downloads/tq-A805-3.log'); | |
$timerQueue = new TimerQueue; | |
$line = 0; | |
while ($input !== '') { | |
$type = $input[0]; | |
$input = \substr($input, 1); | |
\assert(\is_string($input)); | |
// print ++$line . "\n"; | |
if ($type === 'i') { | |
$expiration = \unpack('Nexpiration', \substr($input, 0, 4))['expiration']; | |
$input = \substr($input, 4); | |
\assert(\is_string($input)); | |
$watcherId = \substr($input, 0, $pos = \strpos($input, "\n")); | |
$input = \substr($input, $pos + 1); | |
\assert(\is_string($input)); | |
$watcher = new Watcher; | |
$watcher->id = $watcherId; | |
$timerQueue->insert($watcher, $expiration); | |
} elseif ($type === 'e') { | |
$now = \unpack('Nnow', \substr($input, 0, 4))['now']; | |
$input = \substr($input, 5); | |
\assert(\is_string($input)); | |
$timerQueue->extract($now); | |
} elseif ($type === 'r') { | |
$watcherId = \substr($input, 0, $pos = \strpos($input, "\n")); | |
$input = \substr($input, $pos + 1); | |
\assert(\is_string($input)); | |
$watcher = new Watcher; | |
$watcher->id = $watcherId; | |
$timerQueue->remove($watcher); | |
} else { | |
throw new \Exception('Invalid type: ' . bin2hex($type) . ' ' . bin2hex($input)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment