Home > Article > Backend Development > Can PHP's readfile read images?
php's readfile() function reads a file and writes it to the output buffer.
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!