It is recommended that you run link checker once a day via crontab and store its current state somewhere instead of checking it on every script load.
Also please notice that this way is only acceptable if you have allow_url_fopen = On in your PHP config or in .htaccess for your site. Else you will have to implement this logic using sockets.