K
K
Kirill Gorelov2015-12-25 23:30:04
PHP
Kirill Gorelov, 2015-12-25 23:30:04

Website accessibility check, how to check several?

Hello.
There is a script which checks availability of the server.

function isDomainAvailible($domain)
       {
               //проверка на валидность урла
               if(!filter_var($domain, FILTER_VALIDATE_URL))
               {
                       return false;
               }
               //инициализация curl
               $curlInit = curl_init($domain);
               curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
               curl_setopt($curlInit,CURLOPT_HEADER,true);
               curl_setopt($curlInit,CURLOPT_NOBODY,true);
               curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
               //получение ответа
               $response = curl_exec($curlInit);
               curl_close($curlInit);
               if ($response) return true;
               return false;
       }
     ?>

How to make it so that not one site is checked, but several?
Just copying this code twice is not very convenient.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
lnked, 2015-12-25
@lnked

Call the function as many times as you like, you can for convenience in a loop or simply, in order:

isDomainAvailible('http://site1.ru');
isDomainAvailible('http://site2.ru');

A
Alexander, 2015-12-26
@Tuborg

Pass multiple domains to the function.
For example, there is an array of 2 sites array('site1','site2');
Just pass the values ​​of the array in the loop

<?php
$domain = array('http://butsw.pp.ua/', 'http://google.com/', 'http://gryazniepisyuni.com/');
foreach ($domain as $url) {
    $is = isDomainAvailible($url);
    if ($is == 1) {
        echo "OK! <br>";
    } else {
        echo "ERR!!!<br>";
    }
}

And the result
42081562140a43fbb1be35efe0ef8121.PNG

E
entermix, 2015-12-26
@entermix

Use curl_multi_init:
php.ru/manual/function.curl-multi-init.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question