phacility / xhprof

XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based user interface.
http://pecl.php.net/package/xhprof
Apache License 2.0
2.6k stars 925 forks source link

Can't open subdirectory of /tmp or /var/tmp #94

Open jennik opened 7 years ago

jennik commented 7 years ago

I faced this problem while using xhprof and php-fpm on centos 7.

If you use php-fpm daemon configured to use private tmp directory (set to true by default in centos 7) and set xhprof.output_dir as subdirectory of /tmp, you probably notice than reports files can't be saved to that dir. In that case you get the following message: "PHP Warning: fopen(/tmp/xhprof/58ed54f13807d.xhprof_testing.xhprof): failed to open stream: No such file or directory in /usr/share/pear/xhprof_lib/utils/xhprof_runs.php on line 136". This happens because of php-fpm service cleans up /tmp directory each time the service started/restarted. So you have to create all subdirectories into /tmp each time you restart php-fpm.

Example:

$ cat /etc/php.d/xhprof.ini 
[xhprof]
extension=xhprof.so
xhprof.output_dir="/tmp/xhprof"
$ cat /usr/lib/systemd/system/php-fpm.service | grep PrivateTmp
PrivateTmp=true
$ sudo ls /tmp/systemd-private-b5096469cfb44152913c896b78570a6d-php-fpm.service-lP5PdF/tmp/xhprof
58f35870bd648.xhprof_testing.xhprof
$ sudo systemctl restart php-fpm
$ sudo ls /tmp/systemd-private-b5096469cfb44152913c896b78570a6d-php-fpm.service-EqBde7/tmp/xhprof
ls: cannot access /tmp/systemd-private-b5096469cfb44152913c896b78570a6d-php-fpm.service-EqBde7/tmp/xhprof: No such file or directory