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 serv开发者_运维问答er. 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.
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.
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();
Try using ImageMagick to resize instead of the normal PHP functions, that might take the load off a bit.
During this upload the server couldn't handle other requests
I find that very surprising, particularly given that there are 2 cores (although you don't say what operating system / webserver you are using). If it's only the image upload functionality which is affected then I suspect that it may be due to issues within your PHP script.
Certainly it may be possible to reduce the amount of load generated by the server during processing. Most of these would involve starting a new compiled process (e.g. via exec) to process the image e.g. from the imageMagick utilities bundle - but without knowing what OS this is, it's impossible to give more specific advice.
In terms of reducing the impact of image conversion, I'd run a managed queue for the incoming images to be processed by. This would ensure you've only got the image handling running on a single core.
精彩评论