Context Options and Parameters Flashcards

1
Q

How are contexts created?

A

stream_context_create()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How are context options set?

A

stream_context_set_option()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are context parameters set?

A

stream_context_set_params()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 7 context options?

A

socket, HTTP, FTP, SSL, CURL, Phar, MongoDB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are socket context options available for?

A

All wrappers that work over sockets, like tcp, http, and ftp.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the socket context options?

A

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().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why can’t the port number for an FTP connection be specified with bindto?

A

Because FTP creates two socket connections during normal operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the HTTP context options?

A

method, header, user_agent, content, proxy, request_fulluri, follow_location, max_redirects, protocol_version, timeout, ignore_errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the FTP context options?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When are CURL context options available?

A

When the CURL extension was compiled using the –with-curlwrappers configure option.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the CURL context options?

A

method, header, user_agent, content, proxy, max_redirects, curl_verify_ssl_host, curl_verify_ssl_peer,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the Phar context options?

A

compress - one of the Phar compression constants

metadata - Phar metadata

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What parameter can be set on a context using the stream_context_set_params() function?

A

notification - a callable to be called when an event occurs on a stream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you register custom stream wrappers?

A

With the stream_wrapper_register() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What URL syntax is supported to describe a wrapper?

A

Only scheme://

scheme:/ and scheme: syntaxes are not supported.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the supported URL-style protocols?

A

file://, http://, ftp://, php:// (for accessing various I/O streams), zlib:// (compression streams), data://, glob://, phar://, ssh2://, rar://, ogg://, expect:// (process interaction systems)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the default wrapper used with PHP?

A

file://

It represents the local filesystem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

When using the CLI sapi, to what directory does file:// default?

A

The directory from which the script was called.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What does the http:// stream do?

A

It allows read-only access to files/resources via HTTP 1.0, using the HTTP GET method.

20
Q

Where can you configure a user_agent string to be used with an http:// stream?

A

In your php.ini file, or in the stream context.

21
Q

Does http:// allow you to access the headers of the resource?

A

The http:// stream allows access to the body of the resource. The headers are stored in the $http_response_header variable.

22
Q

How can you determine the URL of the resource where your document came from, after all redirects have been processed?

A

You’ll need to process the series of response headers returned by the stream.

23
Q

When is HTTPS supported via the https:// stream?

A

Only when the openssl extension is enabled.

24
Q

Can you write data or copy files to an HTTP resource?

A

No. HTTP connections are read-only. Sending POST and PUT requests can be done with the help of HTTP contexts.

25
If the server does not support ______, the ftp:// connection will fail.
passive mode ftp
26
What does the ftp:// or ftps:// stream do?
Allows read access to existing files and creation of new files via FTP.
27
Can you open files for reading and writing via the ftp:// stream?
No. Either reading or writing, but not both simultaneously.
28
What happens if the remote file already exists on the ftp server and you attempt to open it for writing, but have not specified the context option 'overwrite'?
The connection will fail.
29
What do you need to do to overwrite existing files over ftp?
Specify the 'overwrite' option in the context, and open the file for writing. Alternatively, you can use the FTP extension.
30
What is the 'from' directive in php.ini?
The value to be sent as the anonymous FTP password.
31
What are the various php:// streams?
php: //stdin (read-only) php: //stdout (write-only) php: //stderr (write-only) php: //input - a read-only stream that allows you to read raw data from the request body php: //output - a write-only stream that allows you to write to the output buffer mechanism in the same way as print and echo php: //fd - allows direct access to the given file descriptor. For example, php://fd/3 refers to file descriptor 3 php: //memory and php://temp - read/write streams that allow temporary data to be stored in a file-like wrapper php: //filter - a kind of meta-wrapper designed to permit the application of filters to a stream at the time of opening. This is useful with all-in-one file functions such as readfile(), file(), and file_get_contents() where there is otherwise no opportunity to apply a filter to the stream prior to the contents being read.
32
What is the difference between php://input and $HTTP_RAW_POST_DATA?
$HTTP_RAW_POST_DATA depends on special php.ini directives.
33
Is php://input available with enctype="multipart/form-data"?
No.
34
Can a stream opened with php://input be read multiple times?
Prior to PHP 5.6, no.
35
What is the difference between php://memory and php://temp?
php://memory will always store its data in memory, whereas php://temp will use a temporary file once the amount of data stored hits a predefined limit (the default is 2MB).
36
How can the memory limit of php://temp be controlled?
By appending /maxmemory:NN, where NN is the maximum amount of data to keep in memory before using a temporary file, in bytes.
37
What is php://filter?
It's a kind of meta-wrapper designed to permit the application of filters to a stream at the time of opening. This is useful with all-in-one file functions such as readfile(), file(), and file_get_contents(), where there is otherwise no opportunity to apply a filter to the stream prior to the contents being read.
38
Which php I/O streams support stat()?
php://memory and php://temp only
39
What are the php://filter parameters?
resource - required. specifies stream to filter. read - optional write - optional filter list to apply to both chains - any filter lists which are not prefixed by read= or write= will be applied to both the read and write chains as appropriate
40
What is the data:// stream wrapper for?
It allows inclusion of small data items as "immediate" data, as if it had been included externally.
41
What is the phar:// stream wrapper for?
PHP archives.
42
Is the ssh2:// stream wrapper enabled by default?
No. In order to use the ssh2.*:// wrappers you must install the SSH2 extension available from PECL.
43
What are the ssh2.*:// options?
ssh2.shell://, ssh2.exec://, ssh2.tunnel://, ssh2.ftp://, ssh2.scp://
44
What is rar:// for?
RAR archives.
45
Is the rar:// wrapper enabled by default?
No. You must install it from PECL.
46
What is ogg:// for?
Audio streams.
47
What is expect:// for?
Accessing Expect streams for automating interactive applications. The usage is expect://command