Question

I have a PHP website with mobile version and google ads are displayed there. I have received google code from my client for the header and the footer, respectively, and they are not always displaying. I receive a lot of warnings in the automatic error reports looking like this:

fopen(http://pagead2.googlesyndication.com/pagead/ads?...): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

After the question mark in the URL there are some parameters with private information, so I decided to write ... instead of them. I have asked my client to regenerate the codes and he has done so, I have pasted the new code for the header and the footer too, however, when we thought the error is gone we decided to call it a day and after 16 hours I have received 4352 error reports, 95% of them was with google ads, the error being the same, namely: failed to open stream. I wonder why do we see sometimes the ads and why are they not showing up in other cases. Question: When you guys have this errors, what are the steps to get rid of them and show the ads? (Of course I can take out the ads, but then my client would be unhappy, LOL)

EDIT: This is part of the code (confidential information was taken out from it and replaced with 'secret'). I hope that the question makes more sense now.

$GLOBALS['google']['client']='secret';
$GLOBALS['google']['https']=read_global('HTTPS');
$GLOBALS['google']['ip']=read_global('REMOTE_ADDR');
$GLOBALS['google']['markup']='xhtml';
$GLOBALS['google']['output']='xhtml';
$GLOBALS['google']['ref']=read_global('HTTP_REFERER');
$GLOBALS['google']['slotname']='secret';
$GLOBALS['google']['url']=read_global('HTTP_HOST') . read_global('REQUEST_URI');
$GLOBALS['google']['useragent']=read_global('HTTP_USER_AGENT');
Was it helpful?

Solution

Since the errors you mention are on a remote server, Id try to test that server as much as possible.

I'd try to discard a problem with my endpoint, which includes my ISP, my browser, firewall and proxy. After that, I'd try to test the other endpoint.

First, try to look for a pattern on the error logs, try to find if it happens because to many connection in a short time, requests from s specific location, old browser, specific version of browser, etc.

Too many connections on a short time period

This should not be a problem for Google servers, but it may indicate a strange situation and some requests may not be getting the normal or complete HTTP response. You can not really test for this, but you can try to detect it and react.

Old browser - Specific version of browser

May be a bug on the browser is sending an incomplete request, which by coincidence happens to be an invalid one and that points to a non-existent resource. May be the browser has a cache defect and is sending the 404 response without even checking the resource. You test this by using at least two different browsers and private session, that way you discard browser problems, caching and cookies. (This works only for JS).

Requests originated on a specific location

That location may have connection problems, or a defective ISP, or an overzealous caching service, or a problematic proxy. You can not test this, but you can try to detect it and react, for instance, not sending ads to those requests.

Firewall - proxy

Is your client's site name similar to a banned/blocked one? If so, and if by coincidence on a server has happened a typo, you may be affected each time a request passes though. Check on lists of banned sites.

Overload on your clients server

Is your client's site hosted on a shared hosting, or a hosting that may be overused? If so, strange behaviours may happen, for instance related to execution time limit of the command, or because it stablishes too many connections and some have to be dropped out, leaving some connection just hanging and waiting for answer. This is difficult to test, but you can check the server load, do a reverse IP check to see if there are many clients sharing the same IP, do cURL requests and check average time.

Time limit - redirections

There are different time limits on a whole connection process. You can check if there is a problem with this, at least from your system as user and from your client's server. Create a PHP file with a cURL session (fresh connection each time and reusing connection), execute it many times, and check the response time and redirections. Check if you always get the right response from the service, if it takes too long, if there are redirections, if there are redirections every time or just some times, test a different times.

EDIT (from Lajos Árpád)

Ad size mismatch

The code might be applicable for a given size, while you might use a different size. You should try to get information from your client about the issue.

Setting mismatch

This is a more general case for the above, but I described the problem of ad size independently, because ad size mismatch often occurs and it might be the real problem. Also, you should check whether the other important settings match, is there an issue with mishandling of something.

END OF EDIT

In my opinion, this should give you the answer you are looking for, and if it doesn't, you can provide more details on this question that can be useful for somebody else or use the results to ask/report on Google.

OTHER TIPS

fopen was part of the google code and we are not allowed to modify that, so I have to leave it at that even if it is strange

That's a double bind. Get rid of it. If it doesn't work, you can't get it to work.

I have found this nearly 7 (!) years old post complaining about your fopen call not working "on their end".

If some times fopen does works for you and some times it doesn't, you may use conditioned action in your code like this:

        <?php

            // Turn off all error reporting
            error_reporting(0);

          $url = 'http://pagead2.googlesyndication.com/pagead/ads';   //put your real url here
          $fp = fopen($url, 'r');

          // The variable $http_response_header will automagically be generated (array)
          /* you may explore the rsponse by un-commenting  the following
          foreach($http_response_header as $key=>$value){
              echo $key.'='.$value.'<br>';
          }
          */

          $response_code = @explode(' ', $http_response_header[0]);
            $response_code = (int)$response_code[1];

            if($return_code==200){
               // show the ad part
               // echo 'OK';
            } else {
                // whatever
                // echo 'OH.BOY';
            }

        ?>

Another way to go round this will be to use the javascript AdSense code instead. Your client may get you the javascript parts to include in the header/footer etc'. It usually looks like:

    <script type="text/javascript">
    <!-- google_ad_client = "pub-UNIQUE_NUMBER";
    /* 300x250, created dd/mm/yy */
    google_ad_slot = "11111111";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top