Get the App
SLTechnology News&Howtos  ›  Development  › 

Php can't handle too big pictures. How to solve it?

Shulou Source: shulou.com Published: 2022-06-02 10:30:25 10月04日 Update

This article introduces the relevant knowledge of "php can't handle too big pictures". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php can not handle too large pictures of the solution: 1, the PHP memory allocation size adjustment, such as "ini_set (" memory_limit "," 512m ");"; 2, modify the security restrictions.

The operating environment of this paper: Windows7 system, PHP7.1, Dell G3.

What if php can't handle too big pictures?

The problem of memory corruption and timeout caused by PHP large picture operation

The project sometimes needs to collect pictures and process them after collection, such as generating thumbnails, cutting, resizing and so on.

Collection is affected by network and system performance and often exceeds the default response time limit of PHP (30s). Therefore, you should set an acceptable response time before a function that may take a long time to operate:

Set_time_limit (0); / / 0 means no time limit.

After the collection is completed, manipulate the image and other files, such as generating image thumbnails, etc. If the captured file is relatively large (or the original image uploaded by the camera is not cropped and compressed), there will be an error of insufficient memory:

At this point, you need to adjust the memory allocation size of PHP:

Ini_set ("memory_limit", "512m"); / / the default seems to be 128m

Some server environments may have security restrictions that cannot be modified by code at this time, so you need to modify the

Memory_limit = 128m

Options are changed. This memory size refers to the server performance configuration and should not be too large.

This is the end of the content of "php can't handle too big pictures". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Picture processing memory size time limit file adjustment security code content image performance more server environment knowledge system allocation service Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB vpn Shulou Information OPPO Reno