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
Q

If the server does not support ______, the ftp:// connection will fail.

A

passive mode ftp

26
Q

What does the ftp:// or ftps:// stream do?

A

Allows read access to existing files and creation of new files via FTP.

27
Q

Can you open files for reading and writing via the ftp:// stream?

A

No. Either reading or writing, but not both simultaneously.

28
Q

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’?

A

The connection will fail.

29
Q

What do you need to do to overwrite existing files over ftp?

A

Specify the ‘overwrite’ option in the context, and open the file for writing. Alternatively, you can use the FTP extension.

30
Q

What is the ‘from’ directive in php.ini?

A

The value to be sent as the anonymous FTP password.

31
Q

What are the various php:// streams?

A

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
Q

What is the difference between php://input and $HTTP_RAW_POST_DATA?

A

$HTTP_RAW_POST_DATA depends on special php.ini directives.

33
Q

Is php://input available with enctype=”multipart/form-data”?

A

No.

34
Q

Can a stream opened with php://input be read multiple times?

A

Prior to PHP 5.6, no.

35
Q

What is the difference between php://memory and php://temp?

A

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
Q

How can the memory limit of php://temp be controlled?

A

By appending /maxmemory:NN, where NN is the maximum amount of data to keep in memory before using a temporary file, in bytes.

37
Q

What is php://filter?

A

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
Q

Which php I/O streams support stat()?

A

php://memory and php://temp only

39
Q

What are the php://filter parameters?

A

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
Q

What is the data:// stream wrapper for?

A

It allows inclusion of small data items as “immediate” data, as if it had been included externally.

41
Q

What is the phar:// stream wrapper for?

A

PHP archives.

42
Q

Is the ssh2:// stream wrapper enabled by default?

A

No. In order to use the ssh2.*:// wrappers you must install the SSH2 extension available from PECL.

43
Q

What are the ssh2.*:// options?

A

ssh2.shell://, ssh2.exec://, ssh2.tunnel://, ssh2.ftp://, ssh2.scp://

44
Q

What is rar:// for?

A

RAR archives.

45
Q

Is the rar:// wrapper enabled by default?

A

No. You must install it from PECL.

46
Q

What is ogg:// for?

A

Audio streams.

47
Q

What is expect:// for?

A

Accessing Expect streams for automating interactive applications. The usage is expect://command