How do we stop error log "file does not exist"?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do we stop error log "file does not exist"?

Post by simonmlewis »

[text][Sun Mar 17 10:50:45 2013] [error] [client 86.31.23.37] File does not exist: /home/site/public_html/apple-touch-icon.png[/text]

We are getting tens of thousands of things on our error logs.
If someone goes to www.sitename.com/apple-touch-icon.png, it redirects them to our homepage anyway, so why are we getting this?

Anyone know?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: How do we stop error log "file does not exist"?

Post by twinedev »

Do you have anything in your pages that reference that file? If not, perhaps Apple devices automatically check for it like many browsers automatically try to load favicon.ico

Either place an image on the server, or adjust the server to give a different 404 responce.

worse case, you can create a blank file... and if you have SSH access, to make it really funny use this command:

Code: Select all

touch /home/site/public_html/apple-touch-icon.png
(touch is a command that will update the timestamp on the file, and if it doesn't exist, will create an empty file)

-Greg
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we stop error log "file does not exist"?

Post by simonmlewis »

Thank you. The first part of your answer, was the answer.
I read more and it seems Apple devices try to find that file to place on the screen. I wish I'd known, as this site has been like this for years!!!
We have over 30,000 lines in an error log abotu it. Could be even over 100,000 lines.

So hoping this will reduce that somewhat!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: How do we stop error log "file does not exist"?

Post by twinedev »

Yeah, it is getting crazy with all the icons needed now....

Here is good info on it:
http://www.kylejlarson.com/blog/2012/ad ... r-website/
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we stop error log "file does not exist"?

Post by simonmlewis »

Here is another error I don't understand:

[text][18-Mar-2013 12:17:39] PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/site/public_html/includes/product.inc on line 1265[/text]

The code is this:

Code: Select all

$resultrccheck = mysql_query ("SELECT rcstock, photoprimary, price, title FROM products WHERE romancode = '$romancodetick' AND rcstock = 'in stock'");
            $num_rcstock = mysql_num_rows($resultrccheck); 
Now, if there are no results, there are no result. So why is it erroring ont he second line:

Code: Select all

$num_rcstock = mysql_num_rows($resultrccheck); 
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do we stop error log "file does not exist"?

Post by Christopher »

mysql_query() returns a resourse on success and FALSE on error. And FALSE is not a valid resource ID. You should always check for errors after a query.

Code: Select all

$resultrccheck = mysql_query ("SELECT rcstock, photoprimary, price, title FROM products WHERE romancode = '$romancodetick' AND rcstock = 'in stock'");
if (($resultrccheck !== false) && !mysql_errno($resultrccheck)) {
    $num_rcstock = mysql_num_rows($resultrccheck);
} else {
    // deal with error
}
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we stop error log "file does not exist"?

Post by simonmlewis »

Oh wow I didn't know that.

Also what about this code:

Code: Select all

$menu = $_REQUEST['menu'];
if ($menu != "")
{	getMenu();}
And I get the error:
[text][18-Mar-2013 15:51:41] PHP Fatal error: Call to undefined function getmenu() in /home/site/public_html/index.php on line 631[/text]
It's only called if there is a request for it, and there is a request or the site would be permanently errored on the rendered page.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we stop error log "file does not exist"?

Post by simonmlewis »

<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>
This from: http://php.net/manual/en/function.mysql-num-rows.php
Is this incorrect then, or are you simply explaining why this script produces occasional errors?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do we stop error log "file does not exist"?

Post by Christopher »

simonmlewis wrote:Oh wow I didn't know that.

Also what about this code:

Code: Select all

$menu = $_REQUEST['menu'];
if ($menu != "")
{	getMenu();}
And I get the error:
[text][18-Mar-2013 15:51:41] PHP Fatal error: Call to undefined function getmenu() in /home/site/public_html/index.php on line 631[/text]
It's only called if there is a request for it, and there is a request or the site would be permanently errored on the rendered page.
I can't say why getmenu() is not defined. My guess is that it has not been included.

For the code above, I would recommend:

Code: Select all

if (isset($_REQUEST['menu']) && ($_REQUEST['menu'] != "")) {
	$menu = $_REQUEST['menu'];
	getMenu();
}
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we stop error log "file does not exist"?

Post by simonmlewis »

Code: Select all

$menu = $_GET['menu'];
if ($menu != "")
{
function getMenu()
{
$thismenu="includes/menu/".$_GET['menu'].".inc";
if (file_exists($thismenu)) 
  {
   include $thismenu;
  } 
  else 
  {
  echo "<meta http-equiv='Refresh' content='0 ;URL=/error'>";
  }
}}
This is wha tI am using at the moment - incorrect?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do we stop error log "file does not exist"?

Post by Christopher »

Is that code separate from the code that calls getMenu() you posted above?
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we stop error log "file does not exist"?

Post by simonmlewis »

Getmenu calls that script.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How do we stop error log "file does not exist"?

Post by Christopher »

The reason getMenu() is not found is that it is not being included. That should be easy to track down. If the menu file is not being included then it is probably that the relative path is not getting the actual file. Finally, the included code is inside the getMenu() function. How does it get out because getMenu() does not return anything?
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do we stop error log "file does not exist"?

Post by simonmlewis »

Do you mean, it's not being requested in the URL, and that is why the script is running, not finding what's being asked of it, thus erroring ??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: How do we stop error log "file does not exist"?

Post by McInfo »

simonmlewis wrote:[text][Sun Mar 17 10:50:45 2013] [error] [client 86.31.23.37] File does not exist: /home/site/public_html/apple-touch-icon.png[/text]

We are getting tens of thousands of things on our error logs.
If someone goes to http://www.sitename.com/apple-touch-icon.png, it redirects them to our homepage anyway, so why are we getting this?

Anyone know?
You can clean up the error log by running this command:
[text]grep -Ev "File does not exist: [^ ]*/(favicon\.ico|robots\.txt|apple-touch-icon[0-9a-z-]*\.png)(, referer: [^ ]+)?$" error_log > error_log_filtered[/text]
It produces a new file called "error_log_filtered" with errors for commonly-requested files stripped out.

I'm not sure if I agree with the idea of serving an empty icon file.
Post Reply