Im having a little trouble getting this to work, maybe somone sees something im dont? Usually just get a timeout error. I changed the ips and names for posting purposes.
$repeat = 1; // How many times repeat the test
$timeout = 100; // Max time for stablish the conection
$size = 0; // Bytes will be read (and display). 0 for read all
$server = '192.168.1.1'; // IP address
$host = 'www.someplace.com'; // Domain name
$target = '/somepage.php'; // Specific program
$referer = 'http://www.test.com/'; // Referer
$port = 80;
$posts = array ( 'somedata' => 'somevalue');
$method = "POST";
$postValues= '';
if ( is_array( $posts ) ) {
foreach( $posts AS $name => $value ){
$postValues .= urlencode( $name ) . "=" . urlencode( $value ) . '&';
}
$postValues = substr( $postValues, 0, -1 );
$method = "POST";
} else {
$postValues = '';
}
$request = "$method $target$postValues HTTP/1.1\r\n";
$request .= "Host: $host\r\n";
$request .= 'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) ';
$request .= "Gecko/20021204\r\n";
$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.1\r\n";
$request .= "Accept-Language: en-us, en;q=0.50\r\n";
$request .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n";
$request .= "Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n";
$request .= "Keep-Alive: 300\r\n";
$request .= "Connection: keep-alive\r\n";
$request .= "Referer: $referer\r\n";
$request .= "Cache-Control: max-age=0\r\n";
if ( $method == "POST" ) {
$lenght = strlen( $postValues );
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
$request .= "Content-Length: $lenght\r\n";
$request .= "\r\n";
$request .= $postValues;
}
print $request;
die();
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 );
}
}
fclose( $socket );
echo "<hr> $i -- $content $ret";
}