简体   繁体   English

jQuery - Ajax在某些帖子上返回错误500

[英]jQuery - Ajax returning error 500 on some posts

I have some Ajax that has been working on a live site, now it has stopped working. 我有一些Ajax一直在现场工作,现在它已停止工作。 The Ajax should be returning a page but is returning a 500 error (internal server error) . Ajax应该返回一个页面,但返回500错误(内部服务器错误)

The strange thing is I can navigate and post to the page the Ajax is calling, so the page is only not working via an Ajax call ($.post). 奇怪的是我可以导航并发布到Ajax正在调用的页面,因此页面只能通过Ajax调用($ .post)工作。

Another strange thing is it is working fine locally, but not live. 另一个奇怪的事情是它在当地工作正常,但不是活着。 Also all the other Ajax on the site is working. 此外,该网站上的所有其他Ajax都在工作。

Anyone have the foggiest what this might be? 这有什么可能是最模糊的? By the way it's all jQuery with CakePHP. 顺便说一下,它是CakePHP的所有jQuery。

Edit : 编辑

The apache error logs are saying: "Premature end of script headers: php-script, referer..." apache错误日志说:“脚本标题过早结束:php-script,referer ......”

Edit 2 : 编辑2

It all happened when I switched the server over to SSL. 这一切都发生在我将服务器切换到SSL时。 It says above error and then "Port 80". 它说上面的错误,然后是“端口80”。

First off, this has nothing to do with jQuery, AJAX, POST, CakePHP, or HTTP headers. 首先,这与jQuery,AJAX,POST,CakePHP或HTTP标头无关。 The complete error message is "Premature end of script", which means that the PHP process that Apache is using to run the PHP script terminated unexpectedly (ie, before the PHP process finished its part of the Fast CGI protocol). 完整的错误消息是“脚本过早结束”,这意味着Apache用于运行PHP脚本的PHP进程意外终止(即,在PHP进程完成其部分Fast CGI协议之前)。 This generally means that the PHP process crashed or caused a "segmentation fault". 这通常意味着PHP进程崩溃或导致“分段错误”。

PHP segmentation faults can be difficult to troubleshoot, and they should never happen; PHP分段错误可能很难排除故障,它们永远不会发生; PHP should never crash. PHP永远不会崩溃。 The reason why it is crashing could be due to a number of things. 崩溃的原因可能是由于许多事情。 Maybe it is a simple fix, though. 也许这是一个简单的修复。

The first thing that I would do is completely uninstall PHP and install the latest stable version. 我要做的第一件事是完全卸载PHP并安装最新的稳定版本。 If you are running PHP 5.3 and Windows, then you should only use the VC6 binaries (the "VC6 x86 Thread Safe" package); 如果您运行的是PHP 5.3和Windows,那么您应该只使用VC6二进制文件(“VC6 x86 Thread Safe”软件包); the VC9 package will cause PHP to crash when used by Apache. 当使用Apache时,VC9包将导致PHP崩溃。 Reinstalling might fix your problem because extension DLLs/SOs of older releases of PHP might still exist in your extensions directory on the live server. 重新安装可能会解决您的问题,因为较旧版本的PHP的扩展DLL / SO可能仍然存在于实时服务器上的扩展目录中。

If on Windows and using MySQL, the next thing that I would do is make sure that the MySQL bin directory is in the live server's Path . 如果在Windows上并使用MySQL,我要做的下一件事就是确保MySQL bin目录位于实时服务器的Path The reason for doing this is to make sure that libmySQL.dll can be "found" by the OS. 这样做的原因是为了确保操作系统“找到” libmySQL.dll You should be able to SSH into the live server, type mysql --help , and see the MySQL CLI client's usage message. 您应该能够SSH到实时服务器,键入mysql --help ,并查看MySQL CLI客户端的用法消息。 Restart Apache if you add the MySQL bin directory to Path . 如果将MySQL bin目录添加到Path重新启动Apache。

If both of these suggestions do not solve the problem, then please update your question with answers to the following: 如果这两个建议都无法解决问题,请通过以下答案更新您的问题:

  1. Are you using a web host or does a company IT team manage a server for your use? 您是使用网络主机还是公司IT团队管理服务器供您使用?
  2. If using a web host, are you leasing a dedicated server? 如果使用Web主机,您是否租用专用服务器?
  3. What operating system are you running? 你在运行什么操作系统?
  4. What version of PHP are you using? 您使用的是哪个版本的PHP?
  5. What PHP extensions are being loaded? 正在加载什么PHP扩展?
  6. Do you load a Zend extension? 你加载Zend扩展吗?
  7. Do you ever use dl ? 你有没有使用过dl

UPDATE: With version 5.3.6 and later, the PHP project no longer releases "VC6" installers. 更新:对于5.3.6及更高版本,PHP项目不再释放“VC6”安装程序。 The recommendation is to install a build of Apache HTTPD from Apache Lounge and use a "VC9" installer. 建议从Apache Lounge安装Apache HTTPD版本并使用“VC9”安装程序。

Check your apache and php error logs ! 检查你的apache和php error logs it will be in there 它会在那里


The most common cause of this problem is the script dying before sending the complete set of headers, or possibly any at all, to the server. 导致此问题的最常见原因是脚本在将完整的标头集(或可能任何标头)发送到服务器之前死亡。 To see if this is the case, try running the script standalone from an interactive session, rather than as a script under the server. 要查看是否是这种情况,请尝试从交互式会话中独立运行脚本,而不是作为服务器下的脚本运行。 If you get error messages, this is almost certainly the cause of the "premature end of script headers" message. 如果收到错误消息,这几乎肯定是“脚本头过早结束”消息的原因。 Even if the CGI runs fine from the command line, remember that the environment and permissions may be different when running under the web server. 即使CGI从命令行运行正常,请记住在Web服务器下运行时环境和权限可能不同。 The CGI can only access resources allowed for the User and Group specified in your Apache configuration. CGI只能访问Apache配置中指定的用户和组所允许的资源。 In addition, the environment will not be the same as the one provided on the command line, but it can be adjusted using the directives provided by mod_env. 此外,环境与命令行中提供的环境不同,但可以使用mod_env提供的指令进行调整。

The second most common cause of this (aside from people not outputting the required headers at all) is a result of an interaction with Perl's output buffering. 第二个最常见的原因(除了人们根本没有输出所需的标题)是与Perl的输出缓冲交互的结果。 To make Perl flush its buffers after each output statement, insert the following statements around the print or write statements that send your HTTP headers: 要在每个输出语句之后使Perl刷新其缓冲区,请在发送HTTP标头的print或write语句周围插入以下语句:

{
    local ($oldbar) = $|;
    $cfh = select (STDOUT);
    $| = 1;
    #
    # print your HTTP headers here
    #
    $| = $oldbar;
    select ($cfh);
}

This is generally only necessary when you are calling external programs from your script that send output to stdout, or if there will be a long delay between the time the headers are sent and the actual content starts being emitted. 这通常仅在从脚本调用将输出发送到stdout的外部程序时,或者在发送标头和开始发送实际内容之间会有很长的延迟时才需要。 To maximize performance, you should turn buffer-flushing back off (with $| = 0 or the equivalent) after the statements that send the headers, as displayed above. 为了最大限度地提高性能,您应该在发送标头的语句之后关闭缓冲区刷新(使用$ | = 0或等效项),如上所示。

If your script isn't written in Perl, do the equivalent thing for whatever language you are using (eg, for C, call fflush() after writing the headers). 如果您的脚本不是用Perl编写的,那么对于您使用的任何语言都要做同等的事情(例如,对于C,在编写标题后调用fflush())。

Another cause for the "premature end of script headers" message are the RLimitCPU and RLimitMEM directives. “脚本标头过早结束”消息的另一个原因是RLimitCPU和RLimitMEM指令。 You may get the message if the CGI script was killed due to a resource limit. 如果CGI脚本因资源限制而被终止,您可能会收到消息。

In addition, a configuration problem in suEXEC, mod_perl, or another third party module can often interfere with the execution of your CGI and cause the "premature end of script headers" message. 此外,suEXEC,mod_perl或其他第三方模块中的配置问题通常会干扰CGI的执行并导致“脚本标头过早结束”消息。


CPHP: CPHP:

Taken from http://henrik.nyh.se/2007/04/premature-end-of-script-headers-for-cgi-can-be-directory-permissions 摘自http://henrik.nyh.se/2007/04/premature-end-of-script-headers-for-cgi-can-be-directory-permissions

Other than the reasons outlined in the Apache FAQ, the error log message "Premature end of script headers" for a CGI script (in my case a Ruby script on Dreamhost) can also mean that the directory containing the script is world-writable. 除了Apache FAQ中列出的原因之外,CGI脚本的错误日志消息“脚本头的过早结束”(在我的例子中是Dreamhost上的Ruby脚本)也可能意味着包含该脚本的目录是全局可写的。

So folder permissions like drwxr-xrwx can cause this error. 因此像drwxr-xrwx这样的文件夹权限可能会导致此错误。 chmod 755 mydir would change those permissions to drwxr-xr-x and all is well. chmod 755 mydir会将这些权限更改为drwxr-xr-x,一切都很好。

I suppose Apache/suEXEC takes issue with running stuff that any evil user can edit. 我想Apache / suEXEC在运行任何恶意用户可以编辑的东西时会遇到问题。

Is worth checking the directory permissions. 值得检查目录权限。

On a separate note, you say that the issue occurred when changing the site to use SSL, however the error mentions port 80. Port 80 is used for standard HTTP traffic however port 443 is used for SSL traffic - if traffic is going via port 80 there could be a server misconfiguration, an HTTP where there should be an HTTPS, or an issue with your certificate. 在单独的说明中,您说在更改站点以使用SSL时出现问题,但是错误提到端口80.端口80用于标准HTTP流量,但端口443用于SSL流量 - 如果流量通过端口80可能存在服务器配置错误,应该存在HTTPS的HTTP或证书问题。 I have seen similar errors occur when a certificate expires. 我看到证书过期时会发生类似的错误。 Are both the URLs (the calling page and the script) using SSL? 使用SSL的URL(调用页面和脚本)都是?

您应该检查php error.log,在我的情况下,我已经使用redis设置了缓存类型,但它无法正常工作。

You can use Fidler to examine what the server returned during that $.post. 您可以使用Fidler检查服务器在$ .post期间返回的内容。 It will contain the webpage which would've been returned if you were to run that same method directly in your browser. 如果您直接在浏览器中运行相同的方法,它将包含将被返回的网页。

This error is a bit of a problematic one because it can be caused by so many things. 这个错误有点问题,因为它可能是由很多东西引起的。

What is your page doing...? 你的页面在做什么......? Here are some suggestions. 以下是一些建议。

If your page is like an auto-complete page, so you pass a bit of information and get a filtered list of results back... Maybe your AJAX script isn't passing back the data item and your page is trying to return everything. 如果您的页面就像一个自动完成的页面,那么您传递一些信息并获得结果的筛选列表...也许您的AJAX脚本没有传回数据项,而您的页面正在尝试返回所有内容。 Really bulky PHP scripts (ie intensive / recursive operations) can cause this error. 真正庞大的PHP脚本(即密集/递归操作)可能会导致此错误。

The normal advice for dealing with this particular error is to strip back to a stable page and then start adding stuff back in - so perhaps point your AJAX script at a page that has this... 处理这个特定错误的正常建议是去掉一个稳定的页面,然后重新开始添加东西 - 所以也许把你的AJAX脚本指向一个有这个的页面......

<?php
    echo 'If this appears, we\'re stable!';
?>

Then gradually add in blocks of your code until you hit a problem. 然后逐渐添加代码块,直到遇到问题。 My suggested version 2 of this page would be... 我建议的本页第2版将是......

<?php
    print_r($_POST);
?>

As this will allow you to check what is coming back in the form post. 因为这将允许您检查表单帖子中的内容。

Failing all of the above, please supply the following... 如果不能满足以上所有要求,请提供以下信息......

1) A description of what your PHP page does, or maybe an example of the code. 1)PHP页面的功能描述,或者代码示例。 2) The JavaScript code that calls the PHP page. 2)调用PHP页面的JavaScript代码。

Perhaps the production site violates the same origin policy . 也许生产站点违反了相同的原始政策

The URL in the browser up to the third slash, must match exactly the URL in your AJAX POST, else the browsers security constraints for Javascript will refuse the response. 浏览器中的URL到第三个斜杠,必须与AJAX POST中的URL完全匹配,否则Javascript的浏览器安全性约束将拒绝响应。 The server may actually see the request and respond correctly, but the browser hands an empty string back to the AJAX call. 服务器实际上可以看到请求并正确响应,但浏览器将空字符串交回给AJAX调用。

I'd like to throw my 2 cents in, but it comes from a slightly different direction and you may or may not have direct resources for troubleshooting - but it's worth thinking about. 我想把我的2美分投入,但它来自一个稍微不同的方向,你可能有或没有直接的资源进行故障排除 - 但值得考虑。

Generally speaking, though, it is a PHP error and we can rule out client side issues. 但一般来说,这是一个PHP错误,我们可以排除客户端问题。 On top of that, in my day job (network troubleshooting), If something is working and then stops, I immediately think "what changed". 最重要的是,在我的日常工作(网络故障排除)中,如果有什么工作然后停止,我会立即想到“改变了什么”。 If you didn't add anything to the script and there's no way for a user to affect the script at runtime, then I would immediately start thinking "uh-oh, what's up with the infrastructure". 如果您没有向脚本添加任何内容,并且用户无法在运行时影响脚本,那么我会立即开始思考“呃 - 哦,基础设施是什么”。 This is especially true if something works locally, but not over the internet. 如果某些东西在本地工作,但不在互联网上,则尤其如此。

Have you checked for bad memory on the server or bad NICs (if bad NICs, that would explain why it works one one interface and not another). 您是否检查过服务器上的内存不良或网卡坏(如果网卡坏了,这可以解释为什么它可以在一个接口而不是另一个接口上工作)。 Do you have access to this or is it hosted (can your host check)? 您是否可以访问此主机或托管主机(您的主机可以检查)吗?

Next I would start thinking, ok, server memory's fine and it's not likely faulty NIC related otherwise it would fail sporatically and at different places. 接下来我会开始思考,好吧,服务器内存很好,并且它不太可能与NIC有关,否则会在不同的地方失败。 Still could be networking, though. 但仍然可以建立网络。 Is there a security device that can mangle packets anywhere in the mix (NIDS/HIDS, WAF, proxy, etc?) Do you see any network problems with packets (duplicates, out of order, Do Not Fragment, etc...). 是否有一个安全设备可以在混合中的任何地方破坏数据包(NIDS / HIDS,WAF,代理等?)您是否看到数据包的任何网络问题(重复,乱序,不碎片等等)。

I'll be honest, if someone called my desk and described your issues to me, first thing I would say is "check the IPS logs" about 85% that's the issue. 老实说,如果有人给我打电话并向我描述了你的问题,我首先要说的是“检查IPS日志”大约85%就是问题。 False positives can do this and all it takes is one auto update on the firewall... 误报可以做到这一点,只需要在防火墙上进行一次自动更新......

I hope that helps. 我希望有所帮助。

我也有这个问题,在我的情况下解决方案是用干净的文件替换php.ini文件。

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

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