目前 PHP 所有的 JWT 库都是用 PHP 语言编写的,为了提高性能,我基于 openssl 库,用 PHP 扩展实现了一个 JWT
GitHub: https://github.com/cdoco/php-jwt
$key = "example-hmac-key"; $claims = array( "data" => [ "name" => "ZiHang Gao", "admin" => true ], "iss" => "http://example.org", "sub" => "1234567890", ); // default HS256 algorithm $token = jwt_encode($claims, $key); echo $token . PHP_EOL; //eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9. //eyJpc3MiOiJodHRwOlwvXC9leGFtcGxlLm9yZyIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiWmlIYW5nIEdhbyIsImFkbWluIjp0cnVlfQ. //2lFeBTsRegsjXiBCZNkW41KFlsZPSFu7KTsyAM9lUiQ print_r(jwt_decode($token, $key)); /** Array ( [data] => Array ( [name] => ZiHang Gao [admin] => 1 ) [iss] => http://example.org [sub] => 1234567890 ) */
![]() | 1 oott123 2018-05-24 10:14:49 +08:00 怎么也得搞个 benchmark 让大家看看你的有多快啊,不然怎么吸引用户 233 |
![]() | 2 qloog 2018-05-24 10:39:01 +08:00 能写出来就至少给个 666 |
![]() | 3 predator 2018-05-24 10:48:14 +08:00 赞一个,7+的暂时只能在测试环境体验下先 |
![]() | 4 gaozihang OP @oott123 我自己跑的 benchmark,是 PHP 的 5-6 倍,后续会把 benchmark 贴出来 ~ |
![]() | 5 wensonsmith 2018-05-24 13:21:30 +08:00 战略 Mark, 666 |