Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server workload increase during php image resize

i have a php script that resize image to three different resolutions on upload. When i upload a image it resizes it to 300*300, 80*80, 800*800 and also saves the original file.

The script that i use is the following link https://github.com/blueimp/jQuery-File-Upload/blob/master/example/upload.php

the following images is the system monitor of the server. The first two spikes of CPU history the resize of the image that takes place when the file is uploaded individually. The following are the files that are uploaded from a queue.

CPU WORKLOAD

During this upload the server couldn't handle other requests. i cannot able to access other pages at that time. either the page loads half or doesn't load at all or the page loads once the upload is complete.

i need immediate solution to this problem. how to overcome this issue. i have to full for the server. is there any pluggin for apache for image resize or is there a problem with the code.

like image 757
Jeyanth Kumar Avatar asked Dec 21 '22 09:12

Jeyanth Kumar


1 Answers

Even if resizing an image took 100% of CPU during a minute, it would still be possible to do other requests: you are using a multi-processes server on a multitasking operating system (and probably with multiple cores too).

However, when you start a PHP session, the session is locked: other requests trying to use the same session have to wait until the first request ends.

This is why you can't do concurrent requests while the image is being resized.

You have to close your session before doing long processing (and eventually re-open it after that).

So, this should fix your problem:

session_write_close();
resize_the_image();
session_start();
like image 177
Arnaud Le Blanc Avatar answered Dec 24 '22 02:12

Arnaud Le Blanc