PHP Context Learning Series "Ten"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.