Tag Archives: Context

Custom Wrappers

stream_wrapper_register(protocol, classname) Registers a protocol; implementation is part of the class

The class implements standard functionality like reading, writing, or changing the file position.

php_user_filter is a predefined class in php and is used in conjunction with user-defined filters.


Stream_context_get_options — Retrieve options for a stream/wrapper/context

Returns an array of options on the specified stream or context.

 $params = array("method" => "POST");
 stream_context_set_default(array("http" => $params));
 echo '<pre>';print_r(stream_context_get_options(stream_context_get_default()));


Stream_context_create — Creates a stream context.

Creates and returns a stream context with any options supplied in options preset.

 $opts = array(
 'header'=>"Accept-language: en\r\n" .
 "Cookie: foo=bar\r\n"

$context = stream_context_create($opts);
 $fp = fopen('http://www.phpcodez.com', 'r', false, $context);

REST Context Switching

o Refers to the act of providing different output based on criteria from the request

o The process inspects the http request headers and/or the request uri, and varies the response appropriately

o Commonly used for:

 providing different output for requests originated via xmlhttprequest

 providing different output based on accept http headers (ex: rest endpoints)

 providing alternate layouts/content based on browser detection