note 59583 added to function.stream-context-create
| From: | net_navard at yahoo dot com | Date: | Sat, 10 Dec 2005 06:38:29 +0000 |
| Subject: | note 59583 added to function.stream-context-create | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99886@lists.php.net to get a copy of this message | ||
Hi,you can create an array of parameters(what it's called a stream context),which can be
transmitted each time you read or write a stream through a socket.In the below example:
$opts =array('http'=>arra('method'=>"GET",
'header'=>"Accept-language:en\r\n"."Cookie: foo=bar\r\n");
What you're actually doing is create a set of parameters(the protocol to be used,the request
method,additional http headers and a cookie) which will be used each time you open a socket
connection to request www.example.com.This saves a lot of time if you want to use these parameters
(called a stream context) whenever you include them when making a request to www.example.com,instead
of having to specify them over and over again.
Using the previous example,say you want to create a stream context,which sends a
"Content-Type" http header and utilize it when making a request to www.example.com.Take a
look:
$opts = array('http'=>array('method'=>"GET",
'header'=>"Content-Type: text/xml; charset=utf-8");
$context = stream_context_create($opts);
$fp = fopen('http://www.example.com','r',false,$context);
fpassthru($fp);
fclose($fp);
Now,when you make a request to www.example.com,the above http header will be included within the
socket and transmitted to the server.Best of luck for you friends,Hossein
----
Manual Page -- http://www.php.net/manual/en/function.stream-context-create.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59583
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59583&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59583&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59583&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59583&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59583&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59583&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59583&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59583&report=yes
Search -- http://master.php.net/manage/user-notes.php