php的$_FILES的临时储存文件与回收机制实测过程
我想有跟我一样的想法的人会这样处理的: 上传的文件只是想临时使用,不需要把原文件保存备用,如resize之类的操作,且这些后期的操作会出现在第二轮从客户端请求时才操作的,如先上传,把上传的临时文件路径返回到浏览器,用户点击后再对这个临时文件进行操作;可是在实际的实现中发现,这个临时文件在二轮请求时,竟然不存在了,跑到临时文件夹中查看也没有找到.
我在某q群中也遇到有人问过这个问题,导致的原因也是跟我的这个实现想法差不多.所以,就有个疑惑,上传文件是怎么个原理?
不想去看php的实现代码,我大概的想了下,应该是一种回收机制:点击了临时文件空间,那么,php自身应该自己维护这块空间的回收;
于是自己尝试上传了一下极大的文件,大到足够让php运行很长时间,我以为我会看到它出现在临时文件夹中.可惜的是,我竟然没有看到它的身影,直到php返回:因为此文件超过上传限制;然后我使用小文件上传打印出它的临时文件夹路径,发现它是以php开头,以tmp结束的文件命名方式;
我想了个方式,使用while卡住上传php的本次进程一定的时间再返回,这回我看到了临时文件夹中的临时文件,确实是以php**.tmp这样的命名,如图
如果在php运行的过程中使用刷新页面的非正常结束php的方式来中止php解析话,那么这个临时文件就会永久的保留,
如果php是正常的结束话,这个文件会在php的结束时删除.
同时我感觉到这个文件应该是在上传完成后再出现的:从我上传大文件看不到它的身影推断;
所以,php的临时文件维护方式是php一结束就回收资源,想在第二轮请求使用这个文件话,应该自己移动后进行维护此文件,
在本次测试中,并没有测试php include多个嵌套情况时,在什么时机下进行回收的.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
