Annotation of embedaddon/php/ext/standard/tests/file/fgets_socket_variation2.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: fgets() over a socket with more than a buffer's worth of data
                      3: --CREDITS--
                      4: Dave Kelsey <d_kelsey@uk.ibm.com>
                      5: --FILE--
                      6: <?php
                      7: 
                      8: // create a file
                      9: $filename = __FILE__ . ".tmp";
                     10: $fd = fopen($filename, "w+");
                     11: 
                     12: // populate the file with lines of data
                     13: define("LINE_OF_DATA", "12345678\n");
                     14: for ($i = 0; $i < 1000; $i++) {
                     15:        fwrite($fd, LINE_OF_DATA);
                     16: }
                     17: fclose($fd);
                     18: 
1.1.1.2 ! misho      19: for ($i=0; $i<100; $i++) {
        !            20:   $port = rand(10000, 65000);
        !            21:   /* Setup socket server */
        !            22:   $server = @stream_socket_server("tcp://127.0.0.1:$port");
        !            23:   if ($server) {
        !            24:     break;
        !            25:   }
        !            26: }
1.1       misho      27: 
                     28: /* Connect to it */
1.1.1.2 ! misho      29: $client = fsockopen("tcp://127.0.0.1:$port");
1.1       misho      30: 
                     31: if (!$client) {
                     32:        die("Unable to create socket");
                     33: }
                     34: 
                     35: /* Accept that connection */
                     36: $socket = stream_socket_accept($server);
                     37: 
                     38: echo "Write data from the file:\n";
                     39: $data = file_get_contents($filename);
                     40: unlink($filename);
                     41: 
                     42: var_dump(fwrite($socket, $data));
                     43: fclose($socket);
                     44: 
                     45: echo "\nRead lines from the client\n";
                     46: while ($line = fgets($client,256)) {
                     47:        if (strcmp($line, LINE_OF_DATA) != 0) {
                     48:                echo "Error - $line does not match " . LINE_OF_DATA;
                     49:                break;
                     50:        }
                     51: }
                     52: 
                     53: echo "\nClose the server side socket and read the remaining data from the client\n";
                     54: fclose($server);
                     55: while(!feof($client)) {
                     56:        fread($client, 1);
                     57: }
                     58: 
                     59: echo "done\n";
                     60: 
                     61: ?>
                     62: --EXPECT--
                     63: Write data from the file:
                     64: int(9000)
                     65: 
                     66: Read lines from the client
                     67: 
                     68: Close the server side socket and read the remaining data from the client
                     69: done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>