PageRenderTime 111ms CodeModel.GetById 102ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/framework/experimental/pherver/HttpServer.php

http://zoop.googlecode.com/
PHP | 85 lines | 41 code | 11 blank | 33 comment | 2 complexity | 4fec9bf640af4073ee07da16d260ab94 MD5 | raw file
 1<?php
 2class HttpServer extends Pherver
 3{
 4	protected function handleNew($newsock)
 5	{
 6	}
 7	
 8	protected function handleRead($read_sock)
 9	{
10		//	read up to 10000 bytes
11		// $data = '';
12		// while(true)
13		// {
14		// 	echo "getting line\n";
15		// 	socket_set_nonblock($read_sock);
16		// 	$line = socket_read($read_sock, 1024, PHP_BINARY_READ);
17		// 	echo "type = " . gettype($line) . "\n";
18		// 	echo "len = " . strlen($line) . "\n";
19		// 	echo "value = $line\n";
20		// 	
21		// 	$err = socket_last_error($read_sock);
22		// 	if($err)
23		// 		echo "error = " . socket_strerror($err) . "\n";
24		// 	else
25		// 		echo "no error\n";
26		// 	
27		// 	if(strlen($line) == 0)
28		// 		break;
29		// 	$data .= $line;
30		// }
31		
32		$data = socket_read($read_sock, 1024, PHP_BINARY_READ);
33		
34		
35		// if(strlen($data) == 5)
36		// 	for($i = 0; $i < strlen($data); $i++)
37		// 		echo "the char is = " . ord($data[$i]) . "\n";
38		
39		echo "start dumping raw data\n";
40		var_dump($data);
41		echo "done dumping raw data\n";
42		
43		// check if the client is disconnected
44		// if ($data === false)
45		if(!$data)
46		{
47			// remove client for $this->clients array
48			$key = array_search($read_sock, $this->clients);
49			unset($this->clients[$key]);
50			echo "client disconnected.\n";
51			// continue to the next client to read from, if any
52			return;
53		}
54		
55		echo "recieving request\n";
56		// check if there is any data after trimming off the spaces
57		if (!empty($data))
58		{
59			echo "printing raw request content\n";
60			echo $data . "\n";
61			// 
62			$message = new HttpMessage($data);
63			
64			echo "printing out message object\n";
65			print_r($message);
66			echo $message->getType() . "\n";
67			echo $message->getRequestMethod() . "\n";
68			echo $message->getRequestUrl() . "\n";
69			
70			HttpResponse::setData("<html><body>asdf</body></html>");
71			
72			print_r(HttpResponse::getRequestHeaders());
73			
74			// HttpResponse::send();
75			// echo "printing the data\n";
76			// echo HttpResponse::getData();
77		}
78		else
79		{
80			echo "received empty request\n";
81			sleep(10);
82		}
83		echo "done receiving request\n\n\n\n";
84	}
85}