FAQ
•
Поиск
Вход
•
Регистрация
Список форумов newssoft.ru
->
PHP
Ответить
Имя
Тема
Сообщение
Смайлики
Дополнительные смайлики
Цвет шрифта:
По умолчанию
Тёмно-красный
Красный
Оранжевый
Коричневый
Жёлтый
Зелёный
Оливковый
Голубой
Синий
Тёмно-синий
Индиго
Фиолетовый
Белый
Чёрный
Размер шрифта:
Размер шрифта
Очень маленький
Маленький
Обычный
Большой
Огромный
Закрыть теги
[quote="admin"][url=https://www.saotn.org/php-curl-check-website-availability/]Ссылка[/url] на источник. Код: [code]<?php /** * PHP/cURL function to check a web site status. If HTTP status is not 200 or 302, or * the requests takes longer than 10 seconds, the website is unreachable. * * Follow me on Twitter: @HertogJanR * * @param string $url URL that must be checked */ function url_test( $url ) { $timeout = 10; $ch = curl_init(); curl_setopt ( $ch, CURLOPT_URL, $url ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_TIMEOUT, $timeout ); $http_respond = curl_exec($ch); $http_respond = trim( strip_tags( $http_respond ) ); $http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); if ( ( $http_code == "200" ) || ( $http_code == "302" ) ) { return true; } else { // return $http_code;, possible too return false; } curl_close( $ch ); } $website = "www.example.com"; if( !url_test( $website ) ) { echo $website ." is down!"; } else { echo $website ." functions correctly."; } ?>[/code][/quote]
Настройки
HTML
ВЫКЛЮЧЕН
BBCode
ВКЛЮЧЕН
Смайлики
ВКЛЮЧЕНЫ
Отключить в этом сообщении BBCode
Отключить в этом сообщении смайлики
Часовой пояс: GMT + 3
Перейти:
Выберите форум
Сервера linux
----------------
Серверные команды
english support
План работ
----------------
В работе
Разработка
----------------
PHP
JS
HTML5 и CSS3
Perl и Ruby
Обзор темы
Автор
Сообщение
admin
Добавлено: Ср Сен 26, 2018 5:40 pm
Заголовок сообщения: Проверка доступности URL
Ссылка
на источник.
Код:
Код:
<?php
/**
* PHP/cURL function to check a web site status. If HTTP status is not 200 or 302, or
* the requests takes longer than 10 seconds, the website is unreachable.
*
* Follow me on Twitter: @HertogJanR
*
* @param string $url URL that must be checked
*/
function url_test( $url ) {
$timeout = 10;
$ch = curl_init();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_TIMEOUT, $timeout );
$http_respond = curl_exec($ch);
$http_respond = trim( strip_tags( $http_respond ) );
$http_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
if ( ( $http_code == "200" ) || ( $http_code == "302" ) ) {
return true;
} else {
// return $http_code;, possible too
return false;
}
curl_close( $ch );
}
$website = "www.example.com";
if( !url_test( $website ) ) {
echo $website ." is down!";
}
else { echo $website ." functions correctly."; }
?>
Powered by
phpBB
© 2001, 2005 phpBB Group
AllSat 22 -
photographe de mariage
- 2006