--- /dev/null
+--TEST--
+stream_get_meta_data() on directories
+--FILE--
+<?php
+
+$dir = opendir(dirname(__FILE__));
+var_dump(stream_get_meta_data($dir));
+closedir($dir);
+
+$dirObject = dir(dirname(__FILE__));
+var_dump(stream_get_meta_data($dirObject->handle));
+
+?>
+--EXPECT--
+array(8) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(3) "dir"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(8) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(3) "dir"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
--- /dev/null
+--TEST--
+stream_get_meta_data() basic functionality
+--FILE--
+<?php
+
+$fp = fopen(__FILE__, "r");
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+?>
+--EXPECTF--
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%sstream_get_meta_data_file_basic.php"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
--- /dev/null
+--TEST--
+Test stream_get_meta_data() function : error conditions
+--FILE--
+<?php
+/* Prototype : proto array stream_get_meta_data(resource fp)
+ * Description: Retrieves header/meta data from streams/file pointers
+ * Source code: ext/standard/streamsfuncs.c
+ * Alias to functions: socket_get_status
+ */
+
+echo "*** Testing stream_get_meta_data() : error conditions ***\n";
+
+// Zero arguments
+echo "\n-- Testing stream_get_meta_data() function with Zero arguments --\n";
+var_dump( stream_get_meta_data() );
+
+//Test stream_get_meta_data with one more than the expected number of arguments
+echo "\n-- Testing stream_get_meta_data() function with more than expected no. of arguments --\n";
+
+$fp = null;
+$extra_arg = 10;
+var_dump( stream_get_meta_data($fp, $extra_arg) );
+
+echo "\n-- Testing stream_get_meta_data() function with invalid stream resource --\n";
+$fp = null;
+var_dump(stream_get_meta_data($fp));
+
+echo "\n-- Testing stream_get_meta_data() function with closed stream resource --\n";
+$fp = fopen(__FILE__, 'r');
+fclose($fp);
+var_dump(stream_get_meta_data($fp));
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing stream_get_meta_data() : error conditions ***
+
+-- Testing stream_get_meta_data() function with Zero arguments --
+
+Warning: Wrong parameter count for stream_get_meta_data() in %s on line %i
+NULL
+
+-- Testing stream_get_meta_data() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for stream_get_meta_data() in %s on line %i
+NULL
+
+-- Testing stream_get_meta_data() function with invalid stream resource --
+
+Warning: stream_get_meta_data(): supplied argument is not a valid stream resource in %s on line %i
+bool(false)
+
+-- Testing stream_get_meta_data() function with closed stream resource --
+
+Warning: stream_get_meta_data(): %i is not a valid stream resource in %s on line %i
+bool(false)
+Done
--- /dev/null
+--TEST--
+stream_get_meta_data() with differing file access modes
+--FILE--
+<?php
+
+// array of all file access modes
+$filemodes = array('r', 'r+', 'w', 'w+', 'a', 'a+', 'x', 'x+',
+ 'rb', 'rb+', 'wb', 'wb+', 'ab', 'ab+', 'xb', 'xb+',
+ 'rt', 'rt+', 'wt', 'wt+', 'at', 'at+', 'xt', 'xt+');
+
+//create a file
+$filename = __FILE__ . '.tmp';
+$fp = fopen($filename, 'w+');
+fclose($fp);
+
+// open file in each access mode and get meta data
+foreach ($filemodes as $mode) {
+ if (strncmp($mode, 'x', 1) == 0) {
+ // x modes require that file does not exist
+ unlink($filename);
+ }
+ $fp = fopen($filename, $mode);
+ var_dump(stream_get_meta_data($fp));
+ fclose($fp);
+}
+
+unlink($filename);
+
+?>
+--EXPECTF--
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "w"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "a"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "a+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "x"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "x+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "rb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "rb+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "wb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "wb+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "ab"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "ab+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "xb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "xb+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "rt"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "rt+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "wt"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "wt+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "at"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "at+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "xt"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(3) "xt+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
--- /dev/null
+--TEST--
+Testing stream_get_meta_data() "unread_bytes" field
+--FILE--
+<?php
+
+$filename = __FILE__ . '.tmp';
+
+$fp = fopen($filename, "w+");
+
+echo "Write some data to the file:\n";
+$i = 0;
+while ($i++ < 20) {
+ fwrite($fp, "a line of data\n");
+}
+
+var_dump(stream_get_meta_data($fp));
+
+//seek to start of file
+rewind($fp);
+
+echo "\n\nRead a line of the file, causing data to be buffered:\n";
+var_dump(fgets($fp));
+
+var_dump(stream_get_meta_data($fp));
+
+echo "\n\nRead 20 bytes from the file:\n";
+fread($fp, 20);
+
+var_dump(stream_get_meta_data($fp));
+
+echo "\n\nRead entire file:\n";
+while(!feof($fp)) {
+ fread($fp, 1);
+}
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+unlink($filename);
+
+?>
+--EXPECTF--
+Write some data to the file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read a line of the file, causing data to be buffered:
+string(15) "a line of data
+"
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(285)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read 20 bytes from the file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(265)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read entire file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
--- /dev/null
+--TEST--
+stream_get_meta_data() with a relative file path
+--FILE--
+<?php
+
+echo "Create a file:\n";
+$filename = __FILE__ . '.tmp';
+$fp = fopen('File://' . $filename, 'w+');
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+echo "\nChange to file's directory and open with a relative path:\n";
+
+$dirname = dirname($filename);
+chdir($dirname);
+$relative_filename = basename($filename);
+
+$fp = fopen($relative_filename, 'r');
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+unlink($filename);
+
+?>
+--EXPECTF--
+Create a file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "File://%sstream_get_meta_data_file_variation4.php.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+Change to file's directory and open with a relative path:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(1) "r"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "stream_get_meta_data_file_variation4.php.tmp"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
--- /dev/null
+--TEST--
+testing stream_get_meta_data() "eof" field for a file stream
+--FILE--
+<?php
+
+$filename = __FILE__ . '.tmp';
+
+$fp = fopen($filename, "w+");
+
+echo "Write some data to the file:\n";
+$i = 0;
+while ($i++ < 20) {
+ fwrite($fp, "a line of data\n");
+}
+
+var_dump(stream_get_meta_data($fp));
+
+//seek to start of file
+rewind($fp);
+
+echo "\n\nRead entire file:\n";
+while(!feof($fp)) {
+ fread($fp, 1);
+}
+
+var_dump(stream_get_meta_data($fp));
+
+fclose($fp);
+
+unlink($filename);
+
+?>
+--EXPECTF--
+Write some data to the file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read entire file:
+array(9) {
+ ["wrapper_type"]=>
+ string(9) "plainfile"
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "w+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(true)
+ ["uri"]=>
+ string(%i) "%s"
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
--- /dev/null
+--TEST--
+Testing stream_get_meta_data() on a process stream.
+--FILE--
+<?php
+
+$output_file = __FILE__.'.tmp';
+$cmd = "echo here is some output";
+$mode = 'rb';
+$handle = popen($cmd, $mode);
+$data = fread($handle, 100);
+
+var_dump(stream_get_meta_data($handle));
+
+pclose($handle);
+
+echo "Done";
+
+?>
+--EXPECT--
+array(7) {
+ ["stream_type"]=>
+ string(5) "STDIO"
+ ["mode"]=>
+ string(2) "rb"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+Done
--- /dev/null
+--TEST--
+stream_get_meta_data() on a udp socket
+--FILE--
+<?php
+
+$tcp_socket = stream_socket_server('tcp://127.0.0.1:31337');
+var_dump(stream_get_meta_data($tcp_socket));
+fclose($tcp_socket);
+
+?>
+--EXPECT--
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
--- /dev/null
+--TEST--
+Testing stream_get_meta_data() "unread_bytes" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+echo "Write some data:\n";
+fwrite($socket, "abcdefg\n1234567\nxyzxyz\n");
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead a line from the client, causing data to be buffered:\n";
+fgets($client);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead 3 bytes of data from the client:\n";
+fread($client, 3);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nClose the server side socket and read the remaining data from the client:\n";
+fclose($socket);
+fclose($server);
+while(!feof($client)) {
+ fread($client, 1);
+}
+var_dump(stream_get_meta_data($client));
+
+?>
+--EXPECT--
+Write some data:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read a line from the client, causing data to be buffered:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(15)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read 3 bytes of data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(12)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Close the server side socket and read the remaining data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
--- /dev/null
+--TEST--
+Testing stream_get_meta_data() "timed_out" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nSet a timeout on the client and attempt a read:\n";
+socket_set_timeout($client, 0, 1000);
+fread($client, 1);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nWrite some data from the server:\n";
+fwrite($socket, "12345");
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead some data from the client:\n";
+fread($client, 5);
+var_dump(stream_get_meta_data($client));
+
+fclose($client);
+fclose($socket);
+fclose($server);
+
+?>
+--EXPECT--
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Set a timeout on the client and attempt a read:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(true)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Write some data from the server:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(true)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read some data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
--- /dev/null
+--TEST--
+Testing stream_get_meta_data() "blocked" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nSet blocking to false:\n";
+var_dump(socket_set_blocking($client, 0));
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nSet blocking to true:\n";
+var_dump(socket_set_blocking($client, 1));
+var_dump(stream_get_meta_data($client));
+
+fclose($client);
+fclose($socket);
+fclose($server);
+
+?>
+--EXPECT--
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Set blocking to false:
+bool(true)
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(false)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Set blocking to true:
+bool(true)
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(0)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
--- /dev/null
+--TEST--
+Testing stream_get_meta_data() "eof" field on a udp socket
+--FILE--
+<?php
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+
+/* Accept that connection */
+$socket = stream_socket_accept($server);
+
+echo "Write some data:\n";
+fwrite($socket, "abcdefg\n1234567\nxyzxyz\n");
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nRead a line from the client:\n";
+fgets($client);
+var_dump(stream_get_meta_data($client));
+
+echo "\n\nClose the server side socket and read the remaining data from the client:\n";
+fclose($socket);
+fclose($server);
+while(!feof($client)) {
+ fread($client, 1);
+}
+var_dump(stream_get_meta_data($client));
+
+fclose($client);
+
+?>
+--EXPECTF--
+Write some data:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(%i)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Read a line from the client:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(%i)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(false)
+}
+
+
+Close the server side socket and read the remaining data from the client:
+array(7) {
+ ["stream_type"]=>
+ string(10) "tcp_socket"
+ ["mode"]=>
+ string(2) "r+"
+ ["unread_bytes"]=>
+ int(%i)
+ ["seekable"]=>
+ bool(false)
+ ["timed_out"]=>
+ bool(false)
+ ["blocked"]=>
+ bool(true)
+ ["eof"]=>
+ bool(true)
+}
\ No newline at end of file
--- /dev/null
+--TEST--
+Test stream_set_timeout() function : error conditions
+--FILE--
+<?php
+/* Prototype : proto bool stream_set_timeout(resource stream, int seconds, int microseconds)
+ * Description: Set timeout on stream read to seconds + microseonds
+ * Source code: ext/standard/streamsfuncs.c
+ * Alias to functions: socket_set_timeout
+ */
+
+/*
+ * add a comment here to say what the test is supposed to do
+ */
+
+echo "*** Testing stream_set_timeout() : error conditions ***\n";
+
+
+//Test stream_set_timeout with one more than the expected number of arguments
+echo "\n-- Testing stream_set_timeout() function with more than expected no. of arguments --\n";
+
+/* Setup socket server */
+$server = stream_socket_server('tcp://127.0.0.1:31337');
+/* Connect to it */
+$client = fsockopen('tcp://127.0.0.1:31337');
+
+$seconds = 10;
+$microseconds = 10;
+$extra_arg = 10;
+var_dump( stream_set_timeout($client, $seconds, $microseconds, $extra_arg) );
+
+// Testing stream_set_timeout with one less than the expected number of arguments
+echo "\n-- Testing stream_set_timeout() function with less than expected no. of arguments --\n";
+
+$seconds = 10;
+var_dump( stream_set_timeout($client) );
+
+
+echo "\n-- Testing stream_set_timeout() function with a closed socket --\n";
+fclose($client);
+var_dump( stream_set_timeout($client, $seconds) );
+
+echo "\n-- Testing stream_set_timeout() function with an invalid stream --\n";
+var_dump( stream_set_timeout($seconds, $seconds) );
+
+echo "\n-- Testing stream_set_timeout() function with a stream that does not support timeouts --\n";
+$filestream = fopen(__FILE__, "r");
+var_dump( stream_set_timeout($filestream, $seconds) );
+
+fclose($filestream);
+fclose($server);
+
+echo "Done";
+?>
+--EXPECTF--
+*** Testing stream_set_timeout() : error conditions ***
+
+-- Testing stream_set_timeout() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for stream_set_timeout() in %s on line %i
+NULL
+
+-- Testing stream_set_timeout() function with less than expected no. of arguments --
+
+Warning: Wrong parameter count for stream_set_timeout() in %s on line %i
+NULL
+
+-- Testing stream_set_timeout() function with a closed socket --
+
+Warning: stream_set_timeout(): %i is not a valid stream resource in %s on line %i
+bool(false)
+
+-- Testing stream_set_timeout() function with an invalid stream --
+
+Warning: stream_set_timeout(): supplied argument is not a valid stream resource in %s on line %i
+bool(false)
+
+-- Testing stream_set_timeout() function with a stream that does not support timeouts --
+bool(false)
+Done