Suggestion: using UUIDs to uniquely identify records and oth

You have a suggestion for a future version of phpMyFAQ? Then post it here!

Moderator: Thorsten

Post Reply
pt20100201
Posts: 134
Joined: Mon Feb 01, 2010 2:11 pm
Location: Porto . Portugal
Contact:

Suggestion: using UUIDs to uniquely identify records and oth

Post by pt20100201 »

Suggestion: using UUIDs to uniquely identify records and other elements in phpMyFAQ

Dear Thorsten Rinne

There are many methods/strategies to uniquely identify an item in the world - being it a book, a grocery product, a software component, and so on.

One method wildly used in computing areas is the UUID (Universally Unique Identifier) - and the GUID, Globally Unique IDentifier.
There are free implementations of the algorithm(s) written in several languages (JavaScript, PHP, etc).

phpMyFAQ uses an auto-incremented sequential number to identify records - FAQ articles, categories, etc -, that is, IDs. The increment value is user-definable.

While this approach is simple and fast, it may cause some problems (as some users have reported).

Examples
  • If the increment value is changed, there is the possibility of generating an already existing ID.
  • If someone wants to merge two or more (FAQ) databases, the resulting DB may contain duplicated record IDs (the administrator must be aware of this possibility, but errors occur …)
On the other hand, when using rewrite statements on a web server, changing a FAQ’s question text breaks bookmarks and links on external sites (search engines pages, etc).

This situation may also occur after changing a FAQ’s category.

So, using UUIDs “v.4” [1] or “v.5” [1] to identify records (and other elements) is an option in order to minimize this kind of situation (it is possible to generate duplicated UUIDs but the probability is very low).

Generating a new UUID ID is slower than generating a new numeric ID - but it happens only once per record/entry.

A UUID “v.4”/”v.5” value can’t be used to sort records by their creation [2] sequence - and comparing strings is slower than comparing numbers -, so for this purpose it is possible to use an extra numeric field (similar to the current record ID) or just the numeric value of the creation date field.


Returning to the rewrite operation.

Using UUIDs, the administrator has two rewrite options:
  • the current approach (with the question’s text – prone to changes and possibly long);
  • the record UUID (“permanent”).
The UUID has also the advantage of being shorter (but not as user friendly as the first option), and may obfuscate the internal query/DB implementation to the external user.

URLs with “v.4” UUIDs don’t need to be URL-encoded (percent-encoding).

Another advantage: the record's UUID value may be used in the RSS <guid> optional element (this avoids feed validators complaints).


Examples
  • Without rewrite statements
    http://faq.example.com/index.php?action=artikel&cat=1&id=23&artlang=en
  • With the current rewrite method
    http://faq.example.com/content/1/23/en/the-question_s-text-that-is-prone-to-changes_and-possibly-long_very-long-or-with-diacritic-characters.html
  • Using UUIDs on the rewrite
    http://faq.example.com/a7a67b6c-f7c8-4dc4-9da5-235a64d48e5a

For non-specialists
[1] RFC 4122. More recent documentation about this subject is available.
[2] A UUID “v.1” contains the creation date/time but has security problems – it includes the host MAC address.
[3]


Kind regards
2010-12-28
pt20100201
Thorsten
Posts: 15562
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Suggestion: using UUIDs to uniquely identify records and

Post by Thorsten »

Hi,

very nice idea... we added something similiar for FAQs back in phpMyFAQ 1.6: the solution ID. It's also an unique ID, starting with 1000 by default and you can get every record this way:

http://faq.phpmyfaq.de/solution_id_1007.html

But using a UUID for more than FAQs is a good idea, there's a PECL extension for that, too: http://pecl.php.net/package/uuid

I'll add it on my roadmap!

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply