|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-11-07 15:51 UTC] manuel-php at mausz dot at
Description: ------------ PHP's temp. directory get cached during multiple requests because php_shutdown_temporary_directory() is only called during module shutdown. Should be during request shutdown. Test script: --------------- no script, but instructions: - set up mod_php + two vhosts with different sys_temp_dir ini-setting - only allow *1* worker (StartServers = MinSpareServers = MaxSpareServers = MaxClients = 1) - turn keepalive off - request sys_get_temp_dir() from both vhosts -> temp dir will be the same PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 11:00:01 2025 UTC |
We are affected by this issue on mod_php 5.6.7 on FreeBSD and Ubuntu since we have started to use a separate temporary directory for every separate VirtualHost, such as: php_admin_value sys_temp_dir /home/foo/tmp Unfortunately the sys_get_temp_dir() return value gets mixed up between virtual hosts. It's easy to reproduce, just use Apache with mod_prefork and mod_php5. Configure a different 'sys_temp_dir' value for two virtualhosts, and put a script such as: <?php echo sys_get_temp_dir(); Reload this script on both virtualhosts a few times in two browser tabs, and you will see the value frequently switch from one vhost's sys_temp_dir value to another one's (on both OS). On FreeBSD even /tmp is returned sometimes. It appears that the cause of this mixup is a cache in main/php_open_temporary_file.c: PHPAPI const char* php_get_temporary_directory(TSRMLS_D) { /* Did we determine the temporary directory already? */ if (temporary_directory) { return temporary_directory; } This is supposed to be cleaned by php_shutdown_temporary_directory(). However, that is called at module shutdown and not at request shutdown. Therefore I understand it's liable not to be cleaned between requests, meaning that different VirtualHosts will re-use each other's temporary directory. If in Apache configuration MaxConnectionsPerChild is set to 1, so that Apache processes are never reused, the problem goes away (but this has serious performance implications). However this reinforces the idea that per-request cleanup of the value is not done. In this PR https://github.com/php/php-src/pull/524 the PR author argued php_shutdown_temporary_directory() should be moved to php_request_shutdown(), however jpauli has registered some doubts. For virtual hosting environments it's extremely useful to set the temp directory on a VirtualHost basis, and its malfunction causes issues for instance with Wordpress auto-updating, so it'd really be awesome if this bug could get some love and would like to help if we can.