PHP的图像大小调整期间,服务器的工作量增加 [英] Server workload increase during php image resize

查看:124
本文介绍了PHP的图像大小调整期间,服务器的工作量增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,调整图像上载三个不同的分辨率。当我上传一个图片将它调整为300 * 300,80 * 80,800 * 800和也节省了原始文件。

这是我使用的脚本如下链接 HTTPS ://github.com/blueimp/jQuery-File-Upload/blob/master/example/upload.php

下面的图像是服务器的系统监视。 CPU历史的前两个尖峰发生时该文件被个别地上传图像的大小调整。以下是被从队列中上传的文件。

在此上传服务器无法处理其他请求。我能不能在那个时候访问其他网页。无论是页面加载一半或根本不或页面加载,一旦上传完成加载。

我需要立即解决这个问题。如何克服这个问题。我有充分的服务器。是有阿帕奇图像大小调整或任何撑着是否存在与code的一个问题。


解决方案

即使调整图像大小一分钟内把100%的CPU,它仍然有可能做其他的请求:您正在使用一个多进程的服务器一个多任务操作系统(也可能有多个内核太)。

然而,当你启动一个PHP会话,的会话锁定:尝试使用同一个会话的其他请求都为等到第一个请求结束的

这是为什么而正在调整图像尺寸,你不能做的并发请求。

您已经做很久处理之前关闭会话(并最终重新打开之后,它)。

所以,这应该解决您的问题:

  session_write_close();
resize_the_image();
在session_start();

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.

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();

这篇关于PHP的图像大小调整期间,服务器的工作量增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆