*/
$FP =fsockopen ("127.0.0.1", 80); Open Data Flow
if (! $fp)//If an error is turned on
{
echo "Unable to Openn"; Output content
}
else//If open successfully
{
Fwrite ($fp, "get/http/1.0rnrn"); Writing content to a data stream
Stream_set_timeout ($FP, 2); To make a timeout setting
$res =fread ($FP, 2000); Read content
$info =stream_get_meta_data ($FP); Get the data Flow header
Fclose ($FP); Turn off Data flow
if ($info [' timed_out '])//If timed out
{
Echo ' connection timed out! '; Output content
}
Else
{
Echo $res; Output Read content
}
}
Example Two
Create a service-side
$socket =stream_socket_server ("tcp://0.0.0.0:8000", $errno, $ERRSTR);
If creation fails
if (! $socket)
{
echo "$errstr ($errno)
n ";
}
If the creation succeeds
Else
{
Accept Connection
while ($conn =stream_socket_accept ($socket))
{
Write Data
Fwrite ($conn, ' The local time is '. Date (' n/j/y g:i a '). " n ");
Close connection
Fclose ($conn);
}
Close socket
Fclose ($socket);
}
//
$file = "Test.txt"; Definition file
$FP =fopen ($file, "w"); Open Data Flow
if ($FP)//If Open successfully
{
Stream_set_write_buffer ($fp, 0); Set buffer
Fwrite ($fp, $output); Write content
Fclose ($FP); Turn off Data flow
}
http://www.bkjia.com/PHPjc/444820.html www.bkjia.com true http://www.bkjia.com/PHPjc/444820.html techarticle */$fp =fsockopen (127.0.0.1,80);//Open Data stream if (! $fp)//If open error {echo unable to openn;//output} else//if successfully opened {fwrite ($fp, get /HTTP/1.0RNRN);//To number ...