The context is used for all file system or data flow encapsulation protocols.
1. Socket context
The main tcp,http,ftp are these socket-based protocols.
Example of the newly added bindto parameter:
<? PHP $opt Array ( array( ' bindto ' = > ' 192.168.1.1:8000 ', ), ); $context stream_context_create ($opt); Echo false $context );? >
2:http context
Args
Method (string) The remote server supports requests such as Get post.
The header (string) overrides the User-agent defined later.
User_agent (String)
Max_redirects (integer) defaults to a maximum of 20 redirects, set to 1 or 0 times without redirection.
The additional data to be sent by the context (string) behind the header, usually using a post or a put
Protocol_version (float) is 1.0 by default. Let's set him to 1.1. Then you can support chunked transfer decoding (chunked transfer encoding). Take a good look at this. Chunked Transmission decoding
A POST request instance:
<? PHP $postdata Http_build_query ( array( ' var1 ' = ' post1 ', ' var2 = ' post2 ' )); $opts = Array ( ' http '= = array (' method ' = ' post' ,'header' = ') ' Context-type:application/x-www-form-urlencoded ', ' content ' = $postdata )); $content = Stream_context_create ($opts); file_get_contents (' www.examples.com/submit.php ', false, $content);
PHP Context Learning Series "Ten"