We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// namespace goes here /** * JSON decoder */ final class Decoder { private static $simdjsonEnabled = false; public static function setAllowSimdjson(bool $allow): void { self::$simdjsonEnabled = $allow && self::hasWorkingSimdjson(); } public static function hasWorkingSimdjson(): bool { return version_compare(phpversion('simdjson') ?: '0', '2.1.0', '>=') && class_exists('SimdJsonException'); } /** * JSON decodes the given json string $msg * * @throws JsonException */ public static function jsonDecode(string $msg, bool $associative = false) { if (self::$simdjsonEnabled) { try { return simdjson_decode($msg, $associative); } catch (\Exception $e) { // Assume errors are rare and fall through, to return the exact same Error messages } } $decoded = \json_decode($msg, $associative); if (\json_last_error() !== \JSON_ERROR_NONE) { throw new \JsonException(\json_last_error_msg(), \json_last_error()); // requires symfony/polyfill-php73 before php 7.3 } return $decoded; } } Decoder::setAllowSimdjson(true);
use ...\Decoder; var_export(Decoder::jsonDecode('{"a":"b"}', true));
https://github.com/crazyxman/simdjson_php/tree/master/benchmark - for applications that work with long json strings, the extra method call would be worth it
The text was updated successfully, but these errors were encountered:
TysonAndre
No branches or pull requests
https://github.com/crazyxman/simdjson_php/tree/master/benchmark - for applications that work with long json strings, the extra method call would be worth it
The text was updated successfully, but these errors were encountered: