Zend / Apache2: Getting 302 Found When Requesting a URL Several Times

I am programming a REST API with a Zend framework .
When I call the URL several times (for example, 1000 times with 1 request per second) in about 0.2% of cases, instead of receiving 200 OK as an answer, I get 302 Found - so it redirects to another page.
Here is the whole server response:

 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 

So, Zend redirects the page error 500 (internal server error). The question is why - and I just can't figure it out ...
A php page called inserting a single row into a MySQL database and returns a JSON string is all.

Apache2 has about 20 concurrent connections , and the server load is <1, so I really don't understand why requests cause problems.

I know that this is a very difficult problem for remote diagnostics, but good guesses and recommendations on how to solve this problem are more than welcome! Thanks.

This is the vache Apache configuration as requested by @chris:

 <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> 
+8
api php mysql apache2 zend-framework
source share
4 answers

Wow - this was a completely unexpected problem and really hard to understand ...

@AdrianWorld helped me on the right track. In Zend ErrorController, I exit the error message and found the following exception:

 ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) Array 

This is apparently a fairly common problem, as described and resolved here .
The session.gc_probability variable was set to 1 in php.ini , which means that there is a 1% probability for the garbage collector and clearing the /var/lib/php5 directory where php sessions are stored. Apparently, this folder is not writable in www-data , which leads to the indicated error and throws a Zend exception.

Since session.gc_probability only sets the likelihood that the error occurred randomly, that debugging is rather complicated.

In any case, I am happy that it is resolved - thanks for all the hints and guesses :)

0
source share

It looks pretty simple and straightforward to me. This is a 302 redirect, and I can't think of anything in ZF, which redirects by itself; especially on the page with error 500. Error 500 (internal server error) should always return error 500 and should never be redirected to 302. So, you are lucky because you should have some error handling in your RETS API that causes redirection where Something (instead of the usual error page).

Find your redirect code. This can be done using the ZF redirection assistant (inside the controller) or manually (anywhere) using the header () and exit (). When you discover a redirect to either show (exit) with debug_backtrace or a dump to that log file. Also, correct the return code or error handling method.

+2
source share

Note that when you specify an ErrorDocument pointing to a remote URL (i.e. something with a method such as http before it), Apache will send a redirect to the client to tell him where to find the document, even if the document hits that one same server.

http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

I assume that you are using the ErrorDocument directive in your Apache HTTP server configuration, which will then be executed according to 500 errors.

500 errors can be caused by PHP itself. To find out what is going on, you need to look into both the server error log and the php error log (and, naturally, include the PHP error log for it).

Or, as I usually write:

A 500 Internal Sever Error always prompts you to look into the server error log. It contains additional information. Since this is PHP, it is also very likely that it is due to Fatal Error in PHP, so ensuring that PHP error logging and viewing the PHP error log is also very useful. More on internal server internal error

+1
source share

Without additional information about your application, it's pretty hard to guess. My guess is that one of your services (most likely a database) slows down with increasing traffic and I / O. As a result, this may result in a timeout for some PHP connections. This results in an application error and redirects to the error page.

Depending on how well your application with internal logging problems scans logs/application.log , but by default this is not very good with logging.

0
source share

All Articles