简体   繁体   English

内部服务器上传文件时出错

[英]Internal Server Error uploading a file

Error 错误
I have a web app with a mass uploader (Plupload) for photos and when I upload say twenty photos, about six (around 30 %) will fail with an Internal Server Error. 我有一个带有大量照片上传器(Plupload)的Web应用程序,当我上传说20张照片时,大约有6张(约30%)会由于内部服务器错误而失败。 I have checked the Apache error.log for this domain and it has nothing new (I know I'm looking at the right error.log since older errors did show here). 我已经检查了该域的Apache error.log,它没有任何新内容(我知道我在查看正确的error.log,因为此处显示的是旧错误)。

This only happens on my VPS on Dreamhost (my hosting provider) servers while on my development server it runs silky smooth. 这仅在Dreamhost(我的托管提供程序)服务器上的VPS上发生,而在我的开发服务器上,它运行平稳。

Oh, and things used to work just fine a month ago and then just started to fail. 哦, 过去一个月前一切正常,然后才开始失败。 Back then I was using Uploadify and since that used Flash, it was impossible for me to debug where the upload failed. 当时我使用的是Uploadify,并且由于使用Flash,因此无法调试上传失败的地方。

Files and script 文件和脚本
Uploaded files are photos, all about 100 kB big, even though I've successfully uploaded (and still can) 3 MB photos. 即使我已经成功上传(并且仍然可以上传)3 MB的照片,上传的文件都是照片,大约有100 kB大。 My .htaccess naturally doesn't change during uploads. 我的.htaccess文件在上传过程中自然不会改变。 On the server side is a PHP script that uses GD2 library to move and resize the photo. 服务器端是一个PHP脚本,该脚本使用GD2库移动照片并调整其大小。

Server state 服务器状态
I have recently upgraded my VPS from 300 to 400 MB of RAM. 我最近将VPS从300 MB的RAM升级到了400 MB。 This thing used to work and I upgraded it just so that memory is ruled out as a reason. 这个东西曾经可以工作,我升级它只是为了排除内存。 Also my memory limit for PHP is at 200 MB, so this should sufice. 另外,我对PHP的内存限制为200 MB,因此应该足够了。

I am getting mighty frustrated that Dreamhost does not want to help , stating that "we can not be responsible for an error your code causes" and "We still will not be able to assist you in debugging the issue unfortunately." 我对Dreamhost不想提供帮助感到沮丧,他说“我们不能为您的代码导致的错误负责”和“不幸的是,我们仍然无法协助您调试问题”。
It has been a week of sparse "support" while my app doesn't work and my clients are frustrated. 一周以来,“支持”稀疏,而我的应用程序无法正常工作并且客户感到沮丧。

Questions 问题

  1. Is this kind of "You're on your own" support a standard across the industry, ie would your host handle this differently? 这种“您自己一个人”是否支持整个行业的标准,即您的主机会以不同的方式处理吗?
  2. How exactly can I debug this? 我究竟是如何调试吗?

I'm going to assume that you have a standard Apache + PHP setup. 我将假设您具有标准的Apache + PHP设置。 One possible configuration is the pre-forked setup; 一种可能的配置是预分支设置。 in this case Apache will adapt to system load by forking more children of itself. 在这种情况下,Apache将通过派生更多子代来适应系统负载。

With only 400 MB of RAM you're pretty tight, so if you're running 20 processes that each take 200MB (assuming every process handles pretty big files using GD) you're getting into some hot waters with the memory manager. 仅有400 MB的RAM,您的内存非常紧张,因此,如果您运行20个进程,每个进程占用200MB的内存(假设每个进程使用GD处理相当大的文件),那么内存管理器就会陷入困境。

I would reduce the total number of instances to 2 first to see how this will go; 我先将实例总数减少到2,以了解情况如何。 also keep an eye on the memory usage by running top . 还可以通过运行top监视内存使用情况。

Regardless, it might be beneficial for you to run a separate task manager such as Gearman to perform resize tasks so that the upload only has to focus on moving the uploaded file and run the resize task; 无论如何,运行单独的任务管理器(例如Gearman)来执行调整大小的任务可能对您是有益的,这样上传仅需专注于移动上传的文件并运行调整大小任务; this way you can greatly reduce the memory required to run your PHP instances. 这样,您可以大大减少运行PHP实例所需的内存。

As to your Q1: the simple answer is that you get what you pay for. 关于您的Q1:简单的答案是您得到了所支付的费用。 A 300Mb RAM Dreamhost VPS costs ~$360 per annum . 300Mb RAM Dreamhost VPS 每年费用约为360 美元 For this you get the VPS service and responses on service failure relating to the provision of the virtual environment. 为此,您可以获得VPS服务以及与提供虚拟环境有关的服务故障的响应。 The OS, the software stack and the applications are outside this service scope. 操作系统,软件堆栈和应用程序不在此服务范围之内。 Why? 为什么? This sort of custom knowledge-base support could cost $50-300 per hour . 这种定制的知识库支持每小时的费用为50-300 美元 You are being unreasonable and deluding yourself if you expect Dreamhost to provide such services pro-bono. 如果您期望Dreamhost无偿提供此类服务,那您就是不讲理和自欺欺人。 That's what sites like this one do. 这就是此类网站所要做的。

So my suggestion is that you suck up that anger and frustration and work out how to help yourself. 因此,我的建议是,您应该吸收这种愤怒和沮丧,并设法解决自己的问题。

As to your Q2. 至于你的Q2。 (i) You need to understand where your Apache errors go to; (i)您需要了解Apache错误的去向; (ii) Ditto any SQL errors if you are using a D/B. (ii)如果您使用的是D / B,则同理所有SQL错误。 (iii) You need to ensure that PHP error logging is enable and verify where the PHP logs are going to. (iii)您需要确保启用了PHP错误日志记录,并确认PHP日志将到达何处。 (iv) You need to inspect those logs, and verify that logging is working correctly, by using a small script which generates runtime errors. (iv)您需要使用生成运行时错误的小脚本来检查那些日志,并验证日志是否正常工作。

You should also consider using enhanced facilities such as php_xdebug to enhance logging levels and introducing application logging. 您还应该考虑使用诸如php_xdebug之类的增强功能来增强日志记录级别并引入应用程序日志记录。

In my experience systems and functions rarely die silently. 以我的经验,系统和功能很少会默默消失。 However, applications programmers often ignore return statuses, etc. For example in the GD library, imagecopyresized() can fail and it returns a status code to tell the application when it has, but if the application doesn't test this status and act accordingly then it can end up going down bizarre execution paths silently, and just appear to the user (or developer) as "it just stopped working". 但是,应用程序程序员经常忽略返回状态等。例如,在GD库中, imagecopyresize()可能会失败,并且会返回状态代码以告知应用程序何时具有该状态,但是如果应用程序未测试该状态并采取相应措施那么它最终可能会悄无声息地沿着怪异的执行路径消失,并向用户(或开发人员)显示为“它刚刚停止工作”。

My last comment is that you should really consider setting up a private VPS within your development environment which mirrors your Dreamhost production config, and use this for integration, acceptance test and support. 我的最后一句话是,您应该真正考虑在开发环境中设置一个专用的VPS,以反映您的Dreamhost生产配置,并将其用于集成,验收测试和支持。 This is pretty easy to do and you can mess this and add debug / what if options and then roll back without polluting your production environment. 这很容易做到,您可以弄乱它并添加debug / if if选项,然后回滚而不污染您的生产环境。 Tools like VMare Appliances and VirtualBox make this easy. 诸如VMare Appliances和VirtualBox之类的工具使此操作变得容易。 See this blog post for a description of how I did this for my hosted service. 请参阅此博客文章 ,以获取有关如何为托管服务执行此操作的说明。

尝试回答问题2:如果您检查了所有代码,但未发现任何错误,我想最好的办法就是检查服务器上运行的所有程序的版本(apache,php, ...),例如,我记得我的Web服务在apache和php上运行时遇到问题,php版本为5.2.8,经过大量调查,我发现该版本解析存在问题xml数据。

Regarding the first part of the question: Dreamhost do offer a paid support service with "call back". 关于问题的第一部分:Dreamhost确实提供带有“回叫”的付费支持服务。 We used this once to get the low down on something. 我们曾经用它来降低某些东西。 They are very good with general support (better than many hosts IMO) but you can't expect dedicated service, and they must handle a lot of piddling questions. 他们在一般支持方面非常出色(比许多主持人IMO要好),但是您不能期望得到专门的服务,因此他们必须处理很多棘手的问题。 But pay for a call back and, in about 2 minutes on the phone, you can get the answer you want, plus they get their $10 (recurring) for the time. 但是要付费回电,在电话上大约2分钟内,您可以获得所需的答案,另外,他们还可以得到10美元(经常性)的费用。 You both win. 你们都赢了 Just remember to cancel the recurring charges. 只要记得取消定期费用即可。

Regarding the second part of the question, we had this very same issue with them. 关于问题的第二部分,我们对他们也有同样的问题。 Their response (as suggested by Linus in the comments) was that they keep a tally of the CPU use of all processes used by your "user". 他们的回应(如Linus在评论中所建议)是,他们对“用户”使用的所有进程的CPU使用情况进行了统计。 If that total exceeds a threshold, they will simply kill the process(es) to get the cycles down. 如果总数超过阈值,他们将简单地终止进程以缩短周期。 No error messages, no warnings, no nothings. 没有错误消息,没有警告,没有。 Processes can include MySQL, CGI (perl) or PHP. 进程可以包括MySQL,CGI(perl)或PHP。 No way to monitor or predict, and we couldn't program round it. 无法监控或预测,我们无法对其进行编程。 Solution... not DreamHost, unfortunately. 解决方案...很不幸,不是DreamHost。 (webhostingtalk.com will give you loads of host ideas). (webhostingtalk.com将为您提供大量的主机创意)。 So we use for some sites, but not for others. 因此,我们用于某些网站,而不用于其他网站。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM