event函数 一定机率报错
运行环境
- PHP 7.4.13 /CentOS Linux release 7.8.2003 (Core)
问题
event() 函数有一定机率报错,经过追踪,是生uuid4报错,偶发
- 初步怀疑是php配置/环境哪里不对,php是手工安装的,装了opcache扩展,但关闭了.除此之外和虚拟机并没有不同.
文件位置: vendor/ramsey/uuid/src/UuidFactory.php
//是这个函数调用的
public function uuid4(): UuidInterface
{
$bytes = $this->randomGenerator->generate(16);
return $this->uuidFromBytesAndVersion($bytes, 4);
}
private function uuidFromBytesAndVersion(string $bytes, int $version): UuidInterface
{
/** @var array $unpackedTime */
$unpackedTime = unpack('n*', substr($bytes, 6, 2));
$timeHi = (int) $unpackedTime[1];
$timeHiAndVersion = pack('n*', BinaryUtils::applyVersion($timeHi, $version));
/** @var array $unpackedClockSeq */
$unpackedClockSeq = unpack('n*', substr($bytes, 8, 2));
$clockSeqHi = (int) $unpackedClockSeq[1];//就是这里报错
$clockSeqHiAndReserved = pack('n*', BinaryUtils::applyVariant($clockSeqHi));
$bytes = substr_replace($bytes, $timeHiAndVersion, 6, 2);
$bytes = substr_replace($bytes, $clockSeqHiAndReserved, 8, 2);
if ($this->isDefaultFeatureSet) {
return LazyUuidFromString::fromBytes($bytes);
}
return $this->uuid($bytes);
}
错误日志
- Undefined offset: 1
- #0 /home/www/ec/vendor/ramsey/uuid/src/UuidFactory.php(481): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
- #1 /home/www/ec/vendor/ramsey/uuid/src/UuidFactory.php(387): Ramsey\Uuid\UuidFactory->uuidFromBytesAndVersion()
update
- 如有进展,我会更新
第一次更新
- 安装虚拟机试了下,每次都是成功,没有这个问题虚拟机是centos8/php7.4/laravel8
结束
- 新机器同样的代码没有问题,出问题的机器是因为开始的php是通过宝塔安装的,后来又删除,手动编译安装,把环境搞坏了.
怀疑出现问题,这个生成的数据有问题