Docker,TravisCI,PHPfile upload和间歇性权限错误/ tmp

我有一个间歇性的file upload错误,只发生在特拉维斯:

Warning: file_put_contents(/tmp/customerDownload_1502892540/image.png): failed to open stream: Permission denied (500 Internal Server Error) 

这是一个在PHP 7.1 Docker容器上运行的Symfony 2.8项目。 有一个Behat场景来testing文件由pipe理员上传和用户下载。 我创build该文件的方法如下所示:

 /** * @param string $fileContents * @param Media $file * @return File */ private function createLocalTemporaryFile(string $fileContents, Media $file): File { $tmpDir = '/tmp/customerDownload_' . time(); if (!file_exists($tmpDir)) { mkdir($tmpDir); } $tmpFilePath = $tmpDir . '/' . $file->getName(); file_put_contents($tmpFilePath, base64_decode($fileContents)); $tmpFile = new File(realpath($tmpFilePath)); return $tmpFile; } 

它失败了大约20%的时间,这是一个很大的数字。 但从来没有在当地或在生产。 我已经尝试在/tmp上设置权限来包含www-data用户:组,但是它没有任何作用。 我很困惑,为什么它不能将内容放到一个文件夹中,

任何人都可以提出为什么这可能会发生,或如何确保它不?

我相信这是某种竞争条件和文件命名问题。 我正在使用相同的文件进行testing,也许testing运行速度很快,它试图写一个文件,而不能。 更新了以下方法到目前为止在12个testing中,没有失败。

 /** * @param string $fileContents * @param Media $file * @return File */ private function createLocalTemporaryFile(string $fileContents, Media $file): File { $tmpDir = '/tmp/' . uniqid('customerDownload_', true); mkdir($tmpDir); $tmpFilePath = $tmpDir . '/' . $file->getName(); file_put_contents($tmpFilePath, base64_decode($fileContents)); $tmpFile = new File(realpath($tmpFilePath)); return $tmpFile; }