Why can’t I find files written by PHP-FPM in /tmp?

Last night, I was trying to use XHProf to do a bit of profiling on phpDocumentor. The CLI app runs, XHProf collates statistics and writes the data to /tmp. When I fired up the XHProf web interface, it couldn’t find anything in /tmp. After making absolutely sure there were no permissions issues going on, I still couldn’t figure it out. PHP’s glob() on “/tmp” was absolutely sure that there were no files there, even though there were plenty of files in /tmp. But, if PHP touched a file in /tmp, the glob could see it, but my “ls -l /tmp” could not. The file was both there and not there, depending on how you interrogated the file system.

Starting from Fedora 17, the systemd service for PHP-FPM has a flag enabled called “PrivateTmp”. Whenever PHP-FPM tried to glob /tmp some linux wizardy means that it’s actually globbing /tmp/systemd-private-$sixChars/. It’s actually a nice idea, separating out temporary file space between processes. You just need to be aware that if you’re mixing CLI apps and web apps designed to share files, this will crop up.

The simple fix? Make sure the xhprof’s ini configuration file sets the output directory to anywhere other than /tmp.

Tagged with: , ,
Posted in Linux, PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">