Home >Backend Development >PHP Tutorial >Detailed example code of fsockopen in php_PHP tutorial
" Unable to openn"; //Output content
}
else //If successfully opened
{
fwrite($fp,"get / http/1.0rnrn"); //Write to the data stream Enter the content
stream_set_timeout($fp,2); //Set the timeout
$res=fread($fp,2000); //Read the content
$info=stream_get_meta_data($fp); /Get the data flow header
fclose($fp); ; ; >
//Create the server
$socket=stream_socket_server("tcp://0.0.0.0:8000",$errno,$errstr);
//If the creation fails
if(! $socket)
{
echo "$errstr ($errno)
n";
}
//If the creation is successful
else
{
//Accept connection
while($conn=stream_socket_accept($socket))
{
//Write data
//Close the connection
fclose($conn); }
//Close the socket
fclose($socket);
}
//
$file="test.txt"; //Define file
$fp=fopen($file,"w"); //Open Data stream
if($fp) //If successfully opened
{
stream_set_write_buffer($fp,0); //Set buffer
fwrite($fp,$output); //Write Enter content
fclose($fp); //Close the data stream
}
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 there is an error when opening { echo unable to openn;//Output content} else//If it is successfully opened { fwrite($fp,get / http/1.0rnrn);//To the number...