Open GoogleCodeExporter opened 8 years ago
Same exact issue here, it happened so much and so fast that before I noticed it
I was banned from the whole server while doing testing...
The main site in this case is a WordPress site with its standard SEO htaccess
settings of:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Any help is greatly appreciated.
Original comment by IMakeTy...@gmail.com
on 29 Jun 2011 at 11:49
[deleted comment]
[deleted comment]
[deleted comment]
I'd posted other replies which, over time, proved not to be correct. That is,
the "solutions" still allowed for the occasional gigabyte-filling error_log
loop. The following solution seems actually to work, at least on my Apache
server.
In the original .htaccess file, we see the following lines:
================================================
================================================
DirectoryIndex phpmobilizer.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ phpmobilizer.php?url=$1 [qsa]
================================================
================================================
My error_log loops were always related to my forums, so I added lines to
attempt to catch the "bad" filecalls:
================================================
================================================
# attempted fix to forums PHP loop
RewriteCond %{REQUEST_URI} ^/forum_name/(.*)
RewriteRule ^learning/(.*) http://www.example.com/forum_name/$1 [END]
================================================
================================================
But I still, sometimes, got loops. The loops always relate to the following
lines within the phpmobilizer.class.php file:
================================================
================================================
34 function loadData(){
35 $fp=fopen($this->_url(), "r");
36 while(!feof($fp)){
37 $this->html .= fgets($fp);
38 }
39 fclose($fp);
================================================
================================================
It's in Line 35 that the problem starts. If "$this->_url()" isn't valid, the
script can loop, quickly filling your error_log, hogging all of your CPU's
power, and crashing your site. I'd tried various error-checking before or
within this function, but they only usually worked. Sometimes they still failed.
So I did some more research, and edited the above function as follows:
================================================
================================================
34 function loadData(){
35 // either the URL is valid, or else open the custom 404 page
36 $handle = @fopen($this->_url(), "r") or die("Cannot open file
$this->_url().");
37 // if invalid, above "die" message should not display;
38 // instead, custom 404 page should be read into script via .htaccess
39 // if valid, then file's contents are read into script
40 $fp = fopen($this->_url(), "r");
41 while(!feof($fp)){
42 $this->html .= fgets($fp);
43 }
44 fclose($fp);
================================================
================================================
By using "@fopen" instead of "$fopen", the script returns a Boolean. Either the
Boolean is "true" (so "$this->_url" is a value file call) or else the script
dies (so there can be no loop). But the "die" message was displaying, instead
of the correct ErrorDocument being served.
The point of the "REQUEST_FILENAME" lines in the original .htaccess file was
that invalid URLs were supposed to have been caught before the script was even
called, right? I'd stopped the loops with the script; the .htaccess lines had
not caught the error first. It occurred to me that maybe these lines were not
helpful.
So I commented out those lines, added a rewrite for when the "m.example.com"
subdomain is being asked to view a file that doesn't need to be mobile-ized,
and added custom ErrorDocuments. My mobile-subdomain .htaccess file now looks
like this:
================================================
================================================
DirectoryIndex phpmobilizer.php
RewriteEngine On
# attempted fix to forums PHP loop
RewriteCond %{REQUEST_URI} ^/forum_name/(.*)
RewriteRule ^learning/(.*) http://www.example.com/forum_name/$1 [END]
# original RewriteCond for mobilizer
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ phpmobilizer.php?url=$1 [END]
# error-doc calls
ErrorDocument 403 /custom_403.htm
ErrorDocument 404 /custom_404.htm
================================================
================================================
It's been a couple weeks now, and I've had no loops, not even little ones.
(Before you take these changes "live", of course, you'll need to change
"example.com" to your own domain name, change any particular directory from
"forum_name" to your own directory name, and change "custom_403.htm" and
"custom_404.htm" to your own ErrorDocument calls. If you don't have any
particular directory which needs Rewrites, then comment out, or don't include,
those lines.)
Eliz.
Original comment by stapel.p...@gmail.com
on 30 Jun 2015 at 8:01
Original issue reported on code.google.com by
terryhan...@yahoo.co.uk
on 8 Sep 2010 at 4:14