Context Options and Parameters Flashcards
How are contexts created?
stream_context_create()
How are context options set?
stream_context_set_option()
How are context parameters set?
stream_context_set_params()
What are the 7 context options?
socket, HTTP, FTP, SSL, CURL, Phar, MongoDB
What are socket context options available for?
All wrappers that work over sockets, like tcp, http, and ftp.
What are the socket context options?
bindto - used to specify the IP address and/or the port number that PHP will use to access the network. The syntax is ip:port for IPv4 addresses, and [ip]:port for IPv6 addresses. Setting the IP or the port to 0 will let the system choose the IP and/or port.
backlog - used to limit the number of outstanding connections in the socket’s listen queue. This is only applicable to stream_socket_server().
Why can’t the port number for an FTP connection be specified with bindto?
Because FTP creates two socket connections during normal operation.
What are the HTTP context options?
method, header, user_agent, content, proxy, request_fulluri, follow_location, max_redirects, protocol_version, timeout, ignore_errors
What are the FTP context options?
overwrite - allow overwriting of existing files on server
resume_pos - file offset at which to begin transfer
proxy - proxy FTP request via http proxy server
When are CURL context options available?
When the CURL extension was compiled using the –with-curlwrappers configure option.
What are the CURL context options?
method, header, user_agent, content, proxy, max_redirects, curl_verify_ssl_host, curl_verify_ssl_peer,
What are the Phar context options?
compress - one of the Phar compression constants
metadata - Phar metadata
What parameter can be set on a context using the stream_context_set_params() function?
notification - a callable to be called when an event occurs on a stream.
How do you register custom stream wrappers?
With the stream_wrapper_register() function.
What URL syntax is supported to describe a wrapper?
Only scheme://
scheme:/ and scheme: syntaxes are not supported.
What are the supported URL-style protocols?
file://, http://, ftp://, php:// (for accessing various I/O streams), zlib:// (compression streams), data://, glob://, phar://, ssh2://, rar://, ogg://, expect:// (process interaction systems)
What is the default wrapper used with PHP?
file://
It represents the local filesystem.
When using the CLI sapi, to what directory does file:// default?
The directory from which the script was called.
What does the http:// stream do?
It allows read-only access to files/resources via HTTP 1.0, using the HTTP GET method.
Where can you configure a user_agent string to be used with an http:// stream?
In your php.ini file, or in the stream context.
Does http:// allow you to access the headers of the resource?
The http:// stream allows access to the body of the resource. The headers are stored in the $http_response_header variable.
How can you determine the URL of the resource where your document came from, after all redirects have been processed?
You’ll need to process the series of response headers returned by the stream.
When is HTTPS supported via the https:// stream?
Only when the openssl extension is enabled.
Can you write data or copy files to an HTTP resource?
No. HTTP connections are read-only. Sending POST and PUT requests can be done with the help of HTTP contexts.