search
Homephp教程php手册php的$_FILES的临时储存文件与回收机制实测过程

php的$_FILES的临时储存文件与回收机制实测过程

Jun 13, 2016 am 11:42 AM
filesphpSameandstoreRecycledeal withActual measurementdocumenthavemechanismofprocess

我想有跟我一样的想法的人会这样处理的: 上传的文件只是想临时使用,不需要把原文件保存备用,如resize之类的操作,且这些后期的操作会出现在第二轮从客户端请求时才操作的,如先上传,把上传的临时文件路径返回到浏览器,用户点击后再对这个临时文件进行操作;可是在实际的实现中发现,这个临时文件在二轮请求时,竟然不存在了,跑到临时文件夹中查看也没有找到.

我在某q群中也遇到有人问过这个问题,导致的原因也是跟我的这个实现想法差不多.所以,就有个疑惑,上传文件是怎么个原理?
不想去看php的实现代码,我大概的想了下,应该是一种回收机制:点击了临时文件空间,那么,php自身应该自己维护这块空间的回收;

于是自己尝试上传了一下极大的文件,大到足够让php运行很长时间,我以为我会看到它出现在临时文件夹中.可惜的是,我竟然没有看到它的身影,直到php返回:因为此文件超过上传限制;然后我使用小文件上传打印出它的临时文件夹路径,发现它是以php开头,以tmp结束的文件命名方式;

我想了个方式,使用while卡住上传php的本次进程一定的时间再返回,这回我看到了临时文件夹中的临时文件,确实是以php**.tmp这样的命名,如图
 
如果在php运行的过程中使用刷新页面的非正常结束php的方式来中止php解析话,那么这个临时文件就会永久的保留,
如果php是正常的结束话,这个文件会在php的结束时删除.

同时我感觉到这个文件应该是在上传完成后再出现的:从我上传大文件看不到它的身影推断;
所以,php的临时文件维护方式是php一结束就回收资源,想在第二轮请求使用这个文件话,应该自己移动后进行维护此文件,
在本次测试中,并没有测试php include多个嵌套情况时,在什么时机下进行回收的.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment