我正在从Windows迁移到Unix环境的应用程序中。
经过数小时的调试,我发现了一个由信号量和www-data用户引起的问题,可能还有一些访问问题。
我的新环境是:
-Debian GNU / Linux 9(stretch)(在docker中)
-Symfony 4.2中的应用
-PHP-FPM + nginx
每当请求到控制器时,都会创建一个锁:
class Controller extends AbstractController {
/** ... */
public function create(Request $request): JsonResponse
{
$lock = $this->getLockInstance();
if ($lock->acquire(true)) {
try {
$this->myService->createTicket(...);
} catch (Exception $e) {
return $this->handleResponse($e);
} finally {
$lock->release();
}
}
return $this->handleResponse();
}
protected function getLockInstance(): Lock
{
if (SemaphoreStore::isSupported()) {
$store = new SemaphoreStore();
} else {
$store = new FlockStore($this->kernel->getCacheDir());
}
$factory = new Factory($store);
return $factory->createLock('lock-' . $this->getUniqueId());
}
}
我想使用Symfony Lock Component(https://symfony.com/doc/current/components/lock.html)中的SemaphoreStore类 我还在我的环境php sysvsem扩展上安装了
docker-php-ext-install sysvsem
但是,当发送请求时,我的请求只是挂起而无法在app.log,nginx.log或php-errors.log中看到任何日志。调试后,我发现获取新的Semaphore锁会导致挂起问题。我在其中一个命令中具有相同的“锁定代码”,因此我以root身份运行并进行了处理。
由于我无法真正发现任何错误, 我应该将用户www-data的访问权限授予哪个目录才能访问Semaphore?
为什么PHP不会引发有关日志文件访问问题的任何错误?
我的lsof转储下面:
php-fpm 4816 root DEL REG 0,1 983058 /dev/zero
php-fpm 4816 root 0u CHR 1,3 0t0 865701 /dev/null
php-fpm 4816 root 1u CHR 1,3 0t0 865701 /dev/null
php-fpm 4816 root 2w FIFO 0,10 0t0 982729 pipe
php-fpm 4816 root 3u REG 8,1 0 786982 /tmp/.ZendSem.iZrHjk (deleted)
php-fpm 4816 root 4w FIFO 0,10 0t0 982729 pipe
php-fpm 4816 root 5w FIFO 0,10 0t0 982729 pipe
php-fpm 4816 root 6u unix 0x0000000000000000 0t0 983059 type=STREAM
php-fpm 4816 root 7u unix 0x0000000000000000 0t0 983060 type=STREAM
php-fpm 4816 root 8u IPv6 983061 0t0 TCP *:9000 (LISTEN)
php-fpm 4816 root 9u a_inode 0,11 0 8770 [eventpoll]
php-fpm 4816 root 10r FIFO 0,10 0t0 983062 pipe
php-fpm 4816 root 11r FIFO 0,10 0t0 983064 pipe
php-fpm 4816 root 12r FIFO 0,10 0t0 983063 pipe
php-fpm 4816 root 14r FIFO 0,10 0t0 983065 pipe
php-fpm 4817 www-data cwd unknown /proc/4817/cwd (readlink: Permission denied)
php-fpm 4817 www-data rtd unknown /proc/4817/root (readlink: Permission denied)
php-fpm 4817 www-data txt unknown /proc/4817/exe (readlink: Permission denied)
php-fpm 4817 www-data 0r unknown /proc/4817/fd/0 (readlink: Permission denied)
php-fpm 4817 www-data 1r unknown /proc/4817/fd/1 (readlink: Permission denied)
php-fpm 4817 www-data 2r unknown /proc/4817/fd/2 (readlink: Permission denied)
php-fpm 4817 www-data 3r unknown /proc/4817/fd/3 (readlink: Permission denied)
php-fpm 4817 www-data 5r unknown /proc/4817/fd/5 (readlink: Permission denied)
php-fpm 4818 www-data cwd unknown /proc/4818/cwd (readlink: Permission denied)
php-fpm 4818 www-data rtd unknown /proc/4818/root (readlink: Permission denied)
php-fpm 4818 www-data txt unknown /proc/4818/exe (readlink: Permission denied)
php-fpm 4818 www-data 0r unknown /proc/4818/fd/0 (readlink: Permission denied)
php-fpm 4818 www-data 1r unknown /proc/4818/fd/1 (readlink: Permission denied)
php-fpm 4818 www-data 2r unknown /proc/4818/fd/2 (readlink: Permission denied)
php-fpm 4818 www-data 3r unknown /proc/4818/fd/3 (readlink: Permission denied)
php-fpm 4818 www-data 4r unknown /proc/4818/fd/4 (readlink: Permission denied)
php-fpm 4818 www-data 5r unknown /proc/4818/fd/5 (readlink: Permission denied)
php-fpm 4818 www-data 6r unknown /proc/4818/fd/6 (readlink: Permission denied)
php-fpm 4818 www-data 7r unknown /proc/4818/fd/7 (readlink: Permission denied)
php-fpm 4818 www-data 8r unknown /proc/4818/fd/8 (readlink: Permission denied)
php-fpm 4818 www-data 9r unknown /proc/4818/fd/9 (readlink: Permission denied)
php-fpm 4818 www-data 10r unknown /proc/4818/fd/10 (readlink: Permission denied)