【发布时间】:2013-03-04 12:35:08
【问题描述】:
我正在使用 Zend 框架编写一个 REST API。
当多次调用 url 时(例如每秒 1 个请求 1000 次),在大约 0.2 % 的情况下,而不是得到 200 OK 作为响应,我得到 302 Found - 所以重定向到不同的页面。
这是整个服务器响应:
302 Found Date: Mon, 04 Mar 2013 11:56:04 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.11
Set-Cookie: PHPSESSID=ui9r8jqa63dbom8osknso6eea5; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: /de/default/index/index/error/500
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html; charset=utf-8
所以 Zend 重定向到 error 500(内部服务器错误)页面。问题是为什么 - 我就是想不通...
被调用的 php 页面将 一行插入 MySQL 数据库 并返回一个 JSON 字符串 - 仅此而已。
Apache2 打开了大约 20 个并发连接,服务器负载为
我知道这是一个很难远程诊断的问题,但我们非常欢迎您对如何解决这个问题提出好的猜测和建议!谢谢。
这是@chris 要求的 apache vhost 配置:
<IfModule mod_ssl.c>
<VirtualHost mydomain.tld:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
ServerName www.mydomain.tld
ServerAlias mydomain.tld *.mydomain.tld
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/ssl_access.log combined
# RewriteLog "/var/log/htaccess.log"
# RewriteLogLevel 5
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
SSLOptions +StrictRequire
SSLCertificateFile /etc/apache2/ssl/cert_2013_2014.crt
SSLCertificateKeyFile /etc/apache2/ssl/www.mydomain.tld.key
SSLCACertificateFile /etc/apache2/ssl/intermediate.crt
</VirtualHost>
</IfModule>
【问题讨论】:
-
你点击哪个 URL 来测试这个?您的 API 是否正常进行任何重定向?
-
通常不进行重定向。回复通常是
200 OK。即使调用 url 的脚本保持完全相同,也会发生错误。 -
最后一个标题行之后的文本是什么 (Content-Type: ...) ?响应体?这是一个奇怪的语法......不是 json,不是 php 转储......否则,有 X-Powered-By: PHP 表示重定向来自 php(而不是来自 apache)。
-
我假设 apache 错误日志什么也没说?
-
ZF 永远不应重定向 到错误页面,这就是为什么我询问您的 API 是否在其他地方进行了任何重定向。似乎正在生成错误,但没有正确处理错误。您的 API 中是否有任何错误处理代码?你在使用 Zend_Rest_Server 吗?
标签: php mysql api zend-framework apache2