symfony - Docker, TravisCI, PHP file uploads and intermittent permissions error on /tmp -
i have intermittent file upload error, occurring in travis:
warning: file_put_contents(/tmp/customerdownload_1502892540/image.png): failed open stream: permission denied (500 internal server error)
this symfony 2.8 project running on php 7.1 docker container. there's behat scenario test file uploading administrators , downloading users. method creating file follows:
/** * @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; }
it fails 20% of time significant amount. never locally or in production. i've tried setting permissions on /tmp
include www-data
user:group has no effect. i'm confused why wouldn't able put contents file in directory had created in first place.
can suggest why might happening, or how ensure doesn't?
i believe sort of race condition , file naming issue. i'm using same file tests , perhaps tests running fast enough it's trying write on file , and cannot. updated method following , far in 12 tests, hasn't failed.
/** * @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; }
Comments
Post a Comment