Skip to content

Instantly share code, notes, and snippets.

@lempzz
lempzz / swoole_context.php
Last active March 14, 2022 10:32
Check if script being executed inside Swoole context
<?php
function is_swoole_context() : bool {
return \Swoole\Coroutine::getCid() !== -1;
}
@lempzz
lempzz / stopwatch.php
Last active May 26, 2022 07:10
Small PHP stopwatch for track how long your code executing
<?php
class Stopwatch
{
public static function launch(bool $asMicrotime = true, int $precision = 4) : callable
{
$start = $asMicrotime ? microtime(true) : time();
return function () use ($start, $asMicrotime, $precision) : string {
$finish = $asMicrotime ? microtime(true) : time();