<?php $fp = fsockopen("127.0.0.1", 80); //打开数据流 if (!$fp) //如果打开出错 { echo "unable to openn"; //输出内容 } else //如果成功打开 { fwrite($fp, "get / http/1.0rnrn"); //向数据流写入内容 stream_set_timeout($fp, 2); //进行超时设置 $res = fread($fp, 2000); //读取内容 $info = stream_get_meta_data($fp); //获取数据流报头 fclose($fp); //关闭数据流 if ($info['timed_out']) //如果超时 { echo 'connection timed out!'; //输出内容 } else { echo $res; //输出读取内容 } } //实例二 //创建服务端 $socket = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr); //如果创建失败 if (!$socket) { echo "$errstr ($errno)<br />n"; } //如果创建成功 else { //接受连接 while ($conn = stream_socket_accept($socket)) { //写入数据 fwrite($conn, 'the local time is ' . date('n/j/y g:i a') . "n"); //关闭连接 fclose($conn); } //关闭socket fclose($socket); } // $file = "test.txt"; //定义文件 $fp = fopen($file, "w"); //打开数据流 if ($fp) //如果成功打开 { stream_set_write_buffer($fp, 0); //设置缓冲区 fwrite($fp, $output); //写入内容 fclose($fp); //关闭数据流 }
永久链接:
转载随意!带上文章地址吧。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
