support for php5.6.30
[php-ancillary.git] / test001.php
1 #!/usr/bin/php
2 <?php
3
4 $FILE_SOCKET = "/tmp/test001.sock";
5 $UNIX_SOCKET = "unix://$FILE_SOCKET";
6 if (file_exists($FILE_SOCKET)) {
7     unlink($FILE_SOCKET);
8 }
9
10 $old_umask = umask(0);
11 if (($list = stream_socket_server($UNIX_SOCKET, $err, $errs)) === FALSE) {
12     exit(11);
13 }
14 umask($old_umask);
15
16 $new_socket = stream_socket_accept($list);
17
18 $stream_info = "";
19
20 $fp = ancillary_getstream($new_socket, $stream_info);
21 printf("FP: %d\n", $fp);
22
23 stream_set_blocking ($fp, FALSE);
24
25 if ($fp == FALSE)
26     printf("ERROR\n");
27 else
28     printf("GOOD\n");
29
30 $from = fread($fp, 4096);
31 printf("FROM: [%s]\n", $from);
32
33 $body = "<html><title>Ancillary Test 001</title><body>HERE I AM</body></html>\n";
34
35 fwrite($fp, "HTTP/1.0 200 OK\r\n");
36 fwrite($fp, "Content-type: text/html\r\n");
37 fwrite($fp, "X-Savannah: rapatal\r\n");
38 // fwrite($fp, sprintf("Content-length: %d\r\n", strlen($body)));
39 fwrite($fp, "\r\n");
40
41 fwrite($fp, $body);
42
43 fflush($fp);
44 fclose($fp);
45
46 print_r($stream_info);
47 ?>