Клубове Дир.бг
powered by diri.bg
търси в Клубове diri.bg Разширено търсене

Вход
Име
Парола

Клубове
Dir.bg
Взаимопомощ
Горещи теми
Компютри и Интернет
Контакти
Култура и изкуство
Мнения
Наука
Политика, Свят
Спорт
Техника
Градове
Религия и мистика
Фен клубове
Хоби, Развлечения
Общества
Я, архивите са живи
Клубове Дирене Регистрация Кой е тук Въпроси Списък Купувам / Продавам 23:47 13.07.25 
Клубове/ Компютри и Интернет / PHP Пълен преглед*
Информация за клуба
Тема Re: fopen() [re: sbd]
Автор Magellan (neznam)
Публикувано25.09.03 11:08  




#
# get_http_headers()
# v1.3 - 1999/06/08
#
# Copyright (c) 1998,1999 easyDNS Technologies Inc.
# http://www.easyDNS.com
# info@easyDNS.com
# All rights reserved.
#
# This code provided "As Is" with no warrantees express or implied.
# The author and contributors are not liable for anything good or
# bad that results from your use of this code.
#
# You are free to distribute this for free provided this notice is
# included. Please forward fixes/enhancements to the author for
# inclusion in the next revision.
#
# USAGE:
# array get_http_headers( str url, str [proto], int [timeout]);
#
# url is in the form "http://www.somewhere.com" or "www.somewhere.com"
# proto is optional, default is "HTTP/1.0"
# timeout is optional, default is 10 (seconds)
#
# array is an associative array with the keys set to the header name
# (lowercase) with the first line of headers (the result line)
# split up into:
# $array[protocol] = protocol server used to answer
# $array[result] = i.e. 200 or 301 or 403 or 404, etc
# $array[message] = i.e. "OK" or "FORBIDDEN" etc.
#
# $array[time_used] will be the approximate number of seconds the
# that the request took
#
# If the request times out, $array[result] will be set to 502.
#
# If the URL is invalid, false is returned
#
#
# HISTORY:
#
# v1.3
# 1999/06/08
# from Mark Jeftovic, markjr@easyDNS.com
# - reduced buffer size in polling loop to 80 from 128
# - setsockblocking = 0 by default but 1 if proto
# request is HTTP/1.1 (in which case our own
# timeout is ignored for some reason)
# - only send Host header for HTTP/1.1 requests
# - stripped extra \n before Host header
# - moved parsing to parse_output() function so
# we can still return partial headers on a timeout
#
# v1.2
# 1999/02/24
# from Colin Viebrock, cmv@easyDNS.com
# Speed enhancements and rewrite:
# - check that host exists before trying to open socket
# - socket blocking for a timeout
# - returns $array[time_used] ... just for fun.
#
# v1.1
# 1998/11/24
# from Gary E. Bickford, garyb@slb.com
# Fix for when $path turns out to be null
#
# v1.0
# from Mark Jeftovic, markjr@easyDNS.com
# Original code
#
#

function get_http_headers($url, $proto= "HTTP/1.0", $timeout=10) {
error_reporting(0);
$return = false;
if (substr($url,0,7)== "http://") {
$url = substr($url,7);
}

$parts = parse_url( "http://".$url);

$ips = gethostbynamel($parts[ "host"]);

if ($ips[0]) {
$ip = $ips[0];
$host = $parts[ "host"];
$path = ($parts[ "path"]) ? $parts[ "path"] : "/";
$port = ($parts[ "port"]) ? $parts[ "port"] : 80;

$start = time();
$timeout = $timeout + $start;

if($sock = fsockopen($host, $port)) {
set_socket_blocking($sock, 0);
switch($proto) {
case "HTTP/1.1":
set_socket_blocking($sock, 1);
fputs($sock, sprintf( "HEAD %s %s\n", $path, $proto));
fputs($sock, sprintf( "Host: %s\n\n", $host));
break;
default:
fputs($sock, sprintf( "HEAD %s %s\n\n", $path, $proto));
}

while(!feof($sock) && $t<$timeout) {
$line .= fgets($sock,1);
$t = time();
}
fclose($sock);
$end = time();

if ($t>=$timeout) {
$http = parse_output($line);
$http[ "result"] = 502;
$http[ "message"] = "Timed Out";
$http[ "time_used"] = $end - $start;
$return = $http;
} elseif($line) {
$http = parse_output($line);
$http[ "time_used"] = $end - $start;
$return = $http;
}
}
}
return $return;
}

function parse_output($line) {
$lines = explode( "\n", $line);
if(substr($lines[0],0,4)== "HTTP") {
list($http[ "protocol"], $http[ "result"], $http[ "message"]) = split( "[[:space:]]+",$lines[0],3);
} else if(substr($lines[0],0,7)== "Server:") {
$http[ "server"] = substr($lines[0],8);
}
for ($i=1; $i<count($lines); $i++) {
list($key, $val) = split( ":[[:space:]]*", $lines[$i],2);
$key = strtolower(trim($key));
if ($key) {
$http[$key] = trim($val);
} else {
break;
}
}
return($http);
};





Списанието

Цялата тема
ТемаАвторПубликувано
* fopen() sbd   24.09.03 18:35
. * Re: fopen() Magellan   24.09.03 18:44
. * Re: fopen() nupaT   25.09.03 10:17
. * Re: fopen() Magellan   25.09.03 11:08
. * Re: fopen() sbd   29.09.03 18:21
Клуб :  


Clubs.dir.bg е форум за дискусии. Dir.bg не носи отговорност за съдържанието и достоверността на публикуваните в дискусиите материали.

Никаква част от съдържанието на тази страница не може да бъде репродуцирана, записвана или предавана под каквато и да е форма или по какъвто и да е повод без писменото съгласие на Dir.bg
За Забележки, коментари и предложения ползвайте формата за Обратна връзка | Мобилна версия | Потребителско споразумение
© 2006-2025 Dir.bg Всички права запазени.