php ライブラリ「ramsey/uuid」を使ってUUIDを生成する

php ライブラリ「ramsey/uuid」を使ってUUIDを生成する



  • OS windows10 pro 64bit
  • Apache 2.4.43
  • PHP 7.4.5
  • Composer 1.10.5




composer require ramsey/uuid

Using version ^4.0 for ramsey/uuid
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
  - Installing ramsey/collection (1.0.1): Loading from cache
  - Installing brick/math (0.8.15): Loading from cache
  - Installing ramsey/uuid (4.0.1): Loading from cache
ramsey/uuid suggests installing ext-gmp (Enables faster math with arbitrary-precision integers using GMP.)
ramsey/uuid suggests installing ext-uuid (Enables the use of PeclUuidTimeGenerator and PeclUuidRandomGenerator.)
ramsey/uuid suggests installing ramsey/uuid-doctrine (Allows the use of Ramsey\Uuid\Uuid as Doctrine field type.)
ramsey/uuid suggests installing paragonie/random-lib (Provides RandomLib for use with the RandomLibAdapter)
Package mschop/noteephp is abandoned, you should avoid using it. Use mschop/notee instead.
Writing lock file
Generating autoload files
23 packages you are using are looking for funding.
Use the `composer fund` command to find out more!




ini_set('display_errors', "On");

require_once __DIR__ . '/vendor/autoload.php';
use Ramsey\Uuid\Uuid;

// Timestanpから生成
echo Uuid::uuid1()."<br>";

// MD5から生成
echo Uuid::uuid3(Uuid::NAMESPACE_DNS, 'keywokokoni')."<br>";

// ランダムで生成
echo Uuid::uuid4();