fsockopen" title="Zobacz w manualu PHP" target="_manual()
Szczegulnie kometarze
<?php
$repeat = 100; // How many times repeat the test
$timeout = 100; // Max time for stablish the conection
$size = 16; // Bytes will be read (and display). 0 for read all
$server = '64.246.30.37'; // IP address
$host = 'www.foo.com'; // Domain name
$target = '/poll/answer.asp'; // Specific program
$referer = 'http://www.test.com/'; // Referer
$port = 80;
// Setup an array of fields to get with then create the get string
$gets = array ( 'get_field_1' => 'somevalue', 'get_field_2' => 'somevalue' );
// Setup an array of fields to post with then create the post string
$posts = array ( 'post_field_1' => 'somevalue', 'post_field_2' => 'somevalue' );
// That's all. Now the program proccess $repeat times
$method = \"GET\";
$getValues = '?';
foreach( $gets AS $name => $value ){
$getValues .= urlencode( $name ) . \"=\" . urlencode( $value ) . '&'; }
$getValues = substr( $getValues, 0
, -1
); } else {
$getValues = '';
}
foreach( $posts AS $name => $value ){
$postValues .= urlencode( $name ) . \"=\" . urlencode( $value ) . '&'; }
$postValues = substr( $postValues, 0
, -1
); $method = \"POST\";
} else {
$postValues = '';
}
$request = \"$method $target$getValues HTTP/1.1rn\";
$request .= \"Host: $hostrn\";
$request .= 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) ';
$request .= \"Gecko/20021204rn\";
$request .= 'Accept: text/xml,application/xml,application/xhtml+xml,';
$request .= 'text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,';
$request .= \"image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1rn\";
$request .= \"Accept-Language: en-us, en;q=0.50rn\";
$request .= \"Accept-Encoding: gzip, deflate, compress;q=0.9rn\";
$request .= \"Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66rn\";
$request .= \"Keep-Alive: 300rn\";
$request .= \"Connection: keep-alivern\";
$request .= \"Referer: $refererrn\";
$request .= \"Cache-Control: max-age=0rn\";
if ( $method == \"POST\" ) {
$lenght = strlen( $postValues ); $request .= \"Content-Type: application/x-www-form-urlencodedrn\";
$request .= \"Content-Length: $lenghtrn\";
$request .= \"rn\";
$request .= $postValues;
}
for ( $i = 0; $i < $repeat; $i++ ) {
$socket = fsockopen( $server, $port, $errno, $errstr, $timeout ); fputs( $socket, $request ); if ( $size > 0 ) {
$ret = fgets( $socket, $size ); } else {
$ret = '';
while ( !feof( $socket ) ) { $ret .= fgets( $socket, 4096
); }
}
echo \"<hr> $i -- $content $ret\"; }
?>