Search code examples
phpgravatar

PHP get information if the network isn't in service


I use gravatar for images in my website, but if the network is bad, I would like to know that and use images in other ways. So how can I know if a particular website is not in service?


Solution

  • No need for complex socket and other remote processing. You can verify if the returned image is indeed an image using the PHP GD library:

    if( !$size = getimagesize($filename) ) {
       $image = 'images/default.jpg';
    }