一个较短的 UUID,ASCII85 与 PHP [英] A shorter UUID, ASCII85 with PHP

查看:40
本文介绍了一个较短的 UUID,ASCII85 与 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解了 UUID v4,它几乎是独一无二的,这正是我所需要的.问题是,这个数字太大了,是否可以用更少的字符生成像 Facebook 或 Twitter 这样的 UUID?

I read about the UUID v4 and it's virtually unique, and that's what I need. The problem is, it's a too large number, is it possible to generate UUID's like Facebook or Twitter with fewer characters?

我读了一些帖子,在那里您可以使用 Ascii85 将此代码缩小到 20,但没有看到可靠的 PHP 脚本可以完成这项工作.有人知道一个测试类吗?对于随机 ID,这是存储这 20 个字符的最佳方式,对吗?

I read some post, where you can shrink this code to 20 with Ascii85, but don't see a reliable PHP script doing the job. Someone knows a tested class?? for random ID's it the best way to store this 20 char, right?

--- 编辑---

@大卫施瓦茨

谢谢.我需要在单个服务器中的随机唯一标识符,介于 8 到 16 个字符之间(如果最低,则 20 就可以了).识别具有可读 ID 但不是增量(第一个对象 10001,第二个 10002)的对象的想法,542A4B243J、C63426KJ70、O30V4U1I9P 等方式很好.ID 需要是(至少)6 个 MySQL 表上的主键.对象是在同一台服务器上用 PHP 创建的.

Thanks. I need a random unique identifier in a single server, between 8 and 16 chars (ok 20 is fine if its the lowest). The idea it's to identify objets with readable ID's but NOT incrementals (first objet 10001, second 10002), the way 542A4B243J, C63426KJ70, O30V4U1I9P, etc is fine. The ID's are needed to be primary keys on (at least) 6 MySQL tables. Objets are created with PHP in the same server.

@ta.speot.is

@ta.speot.is

我写道没有看到一个可靠的 PHP 脚本在做这项工作.有人知道一个经过测试的类??"我认为 google 中出现的所有代码都没有经过测试,您是否测试了所有链接?

I wrote "don't see a reliable PHP script doing the job. Someone knows a tested class??" I don't think everything code in appear in google are tested, have you tested all the links maybe??

@sarnold

谢谢,但我很抱歉,不太明白=(

Thanks but I'm sorry, didn't understood well =(

推荐答案

我在处理一个企业项目时遇到了同样的问题,我在 PHP 中找不到合理且经过测试的快速解决方案.所以我决定写一个 PHP 扩展,它可以用 base85/ascii85 编码/解码数据.

I faced the same problem for an enterprise project I was working on, and I couldn't find a reasonable tested and fast solution in PHP. So I decided to write a PHP extension which can be used to encode/decode data with base85/ascii85.

您可以在这里查看:https://github.com/miezuit/php-base85

它使用一组自动化测试进行测试.

It is tested using a set of automated tests.

这篇关于一个较短的 UUID,ASCII85 与 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆