function signal($w) { global $wires; // if solved, return signal if (preg_match('/^\\d+$/', $wires[$w])) { return intval($wires[$w]); } // else if just one input, iterate if (preg_match('/^([a-z]+)$/', $wires[$w])) { return signal($wires[$w]); } // else split preg_match('/(([a-z0-9]+) )?([A-Z]+) ([a-z0-9]+)/', $wires[$w], $split); $a = $split[2]; $op = $split[3]; $b = $split[4]; // solve parts if ($a) { if (!preg_match('/^\\d+$/', $a)) { $a = signal($a); } } if (!preg_match('/^\\d+$/', $b)) { $b = signal($b); } // force ints $a = intval($a); $b = intval($b); // perform bitwise operation if ($op == 'AND') { $wires[$w] = $a & $b; } elseif ($op == 'OR') { $wires[$w] = $a | $b; } elseif ($op == 'XOR') { $wires[$w] = $a ^ $b; } elseif ($op == 'NOT') { $wires[$w] = ~$b; } elseif ($op == 'LSHIFT') { $wires[$w] = $a << $b; } elseif ($op == 'RSHIFT') { $wires[$w] = $a >> $b; } else { die('unexpected operator'); } // return signal return $wires[$w]; }
<?php echo "HERE"; xp_import('time'); $precision = 1000; $signal = new \time\SIG_Awake($precision, TIME_MILLISECONDS); $signal->time = milliseconds(); $precision_timing = []; $function = exhaust(10, function ($signal) use($precision, &$precision_timing) { $timing = intval(floatval(milliseconds() - $signal->time)) - $precision; echo $timing . PHP_EOL; if ($timing > 100000) { // Second change $timing = 0; } $precision_timing[] = [$timing, 0]; $signal->time = milliseconds(); }); signal($signal, $function); on_shutdown(function () use(&$precision_timing) { array_shift($precision_timing); $results = ['msPrecision' => $precision_timing]; ob_start(); include dirname(realpath(__FILE__)) . '/chart.php'; $data = ob_get_contents(); ob_end_clean(); file_put_contents('millisecond_precision.html', $data); echo "Performance chart in millisecond_precision.html" . PHP_EOL; });
<?php xp_import('time'); $precision = 150; $signal = new \time\SIG_Awake($precision, TIME_MICROSECONDS); $signal->time = microtime(true); $precision_timing = []; signal($signal, exhaust(100, function ($signal) use($precision, &$precision_timing) { $timing = intval(floatval(microtime(true) - $signal->time) * 1000000) - $precision; if ($timing > 100000 || $timing < 0) { // Second change $timing = 0; } $precision_timing[] = [$timing, 0]; $signal->time = microtime(true); })); on_shutdown(function () use(&$precision_timing) { array_shift($precision_timing); $results = ['usPrecision' => $precision_timing]; ob_start(); include dirname(realpath(__FILE__)) . '/chart.php'; $data = ob_get_contents(); ob_end_clean(); file_put_contents('precision.html', $data); echo "Performance chart in precision.html" . PHP_EOL; }); /** * Copyright 2010-12 Nickolas Whiting. All rights reserved. * Use of this source code is governed by the Apache 2 license * that can be found in the LICENSE file. */
<?php try { signal("warning"); } catch (bu\def\UncatchedSignalException $e) { echo "catched"; } ?> --- catched