php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77365 tmpfile() is not being cleaned up
Submitted: 2018-12-28 18:00 UTC Modified: 2021-02-12 14:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: gadelat at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 7.2.14RC1 OS: Ubuntu 18.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gadelat at gmail dot com
New email:
PHP Version: OS:

 

 [2018-12-28 18:00 UTC] gadelat at gmail dot com
Description:
------------
Might be duplicate of https://bugs.php.net/bug.php?id=67105 but created this issue anyway, since that report wasn't acknowledged and aims for documentation instead of fixing the cleanup process.

Anyway, bug is that interrupting script via CTRL+C prevents tmpfile cleanup.

Test script:
---------------
tmpfile(); while(true) // execute this and press ctrl+c

Expected result:
----------------
no new php* files in /tmp/

Actual result:
--------------
new php* file in /tmp/

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-30 00:01 UTC] gadelat at gmail dot com
Just found that following for some reason DOES delete the file

<?php

$stream = tmpfile();

pcntl_async_signals(true);
pcntl_signal(SIGINT, function() {
	exit(0);
});

while(true);
 [2018-12-30 09:33 UTC] gadelat at gmail dot com
There is no way in PHP to clean up tmpfiles when script is terminated with ctrl+c in cross platform compatible way :(
 [2018-12-30 14:28 UTC] spam2 at rhsoft dot net
ctrl+c = sigterm and so why should there be no way?
 [2021-02-12 14:16 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-02-12 14:16 UTC] cmb@php.net
This is expected behavior.  The respective documentation has been
fixed in the meantime.

> There is no way in PHP to clean up tmpfiles when script is
> terminated with ctrl+c in cross platform compatible way :(

Well, at least there is a way on Windows as well:

<?php
$stream = tmpfile();
sapi_windows_set_ctrl_handler(function ($event) {exit;});
while(true);
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC