boattowers / phpmobilizer

Automatically exported from code.google.com/p/phpmobilizer
0 stars 0 forks source link

Very large error log each time mobile site is accessed #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What version of the product are you using? On what operating system?
Latest version as of: 8th Sept 2010 on hostgator shared linux server using 
Apache 2.2.16 PHP version: 5.2.14

Additional information below.
Each time the mobile site is accessed is was getting error_log files as large 
as 300mb (which linux system wouldn't let me access to read them)
After adding this...

AddHandler custom-php .php .pcgi .phtml .inc .phtml~ .php~ .inc~ .html~
Action custom-php /cgi-sys/php5

To the .htaccess file

The error_log on each access to the site has been reduced to around 300kb but 
this is 300kb each time the mobile site is accessed.

The error log output is as follows:
[08-Sep-2010 11:00:23] PHP Warning:  
fopen(http://mysite.com/apicture.gif?url=apicture.gif) [<a 
href='function.fopen'>function.fopen</a>]: failed to open stream: Connection 
timed out in /home/myserver/public_html/m/phpmobilizer.class.php on line 35
[08-Sep-2010 11:00:23] PHP Warning:  feof(): supplied argument is not a valid 
stream resource in /home/myserver/public_html/m/phpmobilizer.class.php on line 
36
[08-Sep-2010 11:00:23] PHP Warning:  fgets(): supplied argument is not a valid 
stream resource in /home/myserver/public_html/m/phpmobilizer.class.php on line 
37

The latter two errors on lines 36 and 37 are repeated hundreds of times down 
the error log page.

Have checked php.ini file to make sure fopen setting are correct, php.ini file 
shows:
allow_url_fopen = On
allow_url_include = On

Original issue reported on code.google.com by terryhan...@yahoo.co.uk on 8 Sep 2010 at 4:14

GoogleCodeExporter commented 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

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
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