Home > Backend Development > PHP Problem > Can PHP's readfile read images?

Can PHP's readfile read images?

(*-*)浩
Release: 2023-02-26 09:22:02
Original
2199 people have browsed it

php's readfile() function reads a file and writes it to the output buffer.

Can PHP's readfile read images?

If successful, this function returns the number of bytes read from the file. On failure, the function returns FALSE with an error message. You can hide error output by adding an '@' in front of the function name. (Recommended learning: PHP video tutorial)

Grammar

readfile(filename,include_path,context)
Copy after login

Example

<?php
echo readfile("test.txt");
?>
Copy after login

The above code will output:

There are two lines in this file.
This is the last line.
57
Copy after login

The test is to read 600 pictures using readfile at the same time and display them on the same page. As a result, the php-cgi.exe process increased significantly and the pictures were opened very slowly. , other PHP programs on the same server cannot be opened.

Because the time to read and transmit an image is much longer than that of an ordinary page, the PHP process cannot be released for a long time, causing a large number of php-cgi.exe to be generated. I generated more than 200 of these at most. process.

If it is required once or the website traffic is too large, try not to use PHP's readfile() function to read the image. Generally, the server cannot bear it.

The above is the detailed content of Can PHP's readfile read images?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template