Doc #67105 [NEW]: Fix documentation for tmpfile
| From: | nate at frickenate dot com | Date: | Tue, 22 Apr 2014 00:54:09 +0000 |
| Subject: | Doc #67105 [NEW]: Fix documentation for tmpfile | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-11164@lists.php.net to get a copy of this message | ||
From: nate at frickenate dot com
Operating system: Ubuntu 14.04
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Fix documentation for tmpfile
Description:
------------
The documentation for the tmpfile() function is wrong and misleading:
"The file is automatically removed when closed (for example, by calling
fclose(), or when there are no remaining references to the file handle
returned by tmpfile()), or when the script ends.
For details, consult your system documentation on the tmpfile(3)
function, as well as the stdio.h header file."
The fact is php does *not* use tmpfile(3) for its implementation. That C
function *guarantees* that there will not be a temporary file left on
disk once the program exists, as the file is unlinked even before
tmpfile(3) even returns.
However, as php relies on its own internal implementation of temporary
files instead of using tmpfile(3), not only is the file not unlinked
before returning the handle, but zombie files on disk are possible. This
is shown in the attached test script.
Please update the documentation to not only remove the misleading
information about tmpfile(3), but to explicitly state and warn that the
function does *not* use tmpfile(3). Php devs are used to a C-named
function being C-equivalent, and it causes problems when this is not the
case.
Test script:
---------------
<?php
// 1. run this script from command-line, do steps 2 and 3 while
sleeping.
// 2. check temp directory. file exists, would not be the case with
tmpfile(3).
// 3. ctrl+c quit the running script. temp file is zombied, not
unlinked.
$fh = tmpfile();
sleep(500);
Expected result:
----------------
Technically, I would expect php's tmpfile() to use tmpfile(3). However,
I have seen existing code using tmpfile() and then
stream_get_meta_data() to extract the 'uri' argument to manipulate the
file on disk (ex: using it with ZipArchive::open()). Since a proper
tmpfile(3) implementation would result in no accessible file on disk,
this type of code would break.
So instead update the documentation to reflect that tmpfile() does not
use tmpfile(3) and that zombie temporary files are possible if php exits
unexpectedly.
--
Edit bug report at https://bugs.php.net/bug.php?id=67105&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67105&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67105&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67105&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67105&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67105&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67105&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67105&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67105&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67105&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67105&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67105&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67105&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67105&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67105&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67105&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67105&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67105&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67105&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67105&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67105&r=mysqlcfg