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

Can PHP's readfile read images?

(*-*)浩
(*-*)浩Original
2019-10-11 10:22:432169browse

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)

Example

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

The above code will output:

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

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!

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