stream_context_create
リソースフローコンテキストを作成します
関数名:stream_context_create()
関数関数:ストリームコンテキストを作成します
該当するバージョン:すべてのバージョン
関数の使用:stream_context_create(array $ options =?、array $ params =?):リソース
パラメーター説明:
オプション:ストリームコンテキストのオプションを設定する連想配列。オプションのパラメーターは次のとおりです。
パラメーション:ストリームコンテキストに追加のパラメーターを設定する連想配列。オプションのパラメーターは次のとおりです。
返品値:成功したときにリソースタイプのストリームコンテキストを返し、障害時にfalseを返します。
サンプルコード:
// 创建一个HTTP请求的流上下文$options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-Type: application/json', 'content' => json_encode(array('name' => 'John')), ), ); $context = stream_context_create($options); // 发送HTTP请求$response = file_get_contents('http://example.com/api', false, $context); // 创建一个SSL连接的流上下文$options = array( 'ssl' => array( 'verify_peer' => true, 'cafile' => '/path/to/cert.pem', ), ); $context = stream_context_create($options); // 打开一个SSL连接$socket = stream_socket_client('ssl://example.com:443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context); if (!$socket) { die("Failed to connect: $errstr ($errno)"); } // 其他用法和示例请参考官方文档:https://www.php.net/manual/en/function.stream-context-create.php
注: