💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
参看流扩展https://www.kancloud.cn/a173512/php_note/1690672 ## [PHP流(Stream)的概述与使用详解](https://www.jianshu.com/p/79591db09b5a) ## 流上下文 有些 PHP 流能够接受一系列可选的参数,这些参数叫流上下文,用于定制流的行为。不同的流封装协议使用的流上下文有所不同,流上下文使用 stream\_context\_create() 函数创建,这个函数返回的上下文对象可以传入大多数文件系统函数。 例如,你知道可以使用 file\_get\_contents() 发送 HTTP POST 请求吗?使用一个流上下文对象即可实现: ~~~php $requestBody = '{"username":"nonfu"}'; $context = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => "Content-Type: application/json;charset=utf-8;\r\nContent-Length: " . mb_strlen($requestBody), 'content' => $requestBody ] ]); $response = file_get_contents('https://my-api.com/users', false, $context); ~~~