yeah the problem i had was figuring out how to create my own $SERVER, and $SESSION arrays. well, that wasn't the only problem.
depending how keen you are, you really need to look at how mod_php works in apache.
also, you might want to take a look at nanoweb, it is a webserver written in php that has some basic php support. im pretty sure you need to be running a cgi version of php to get this server to execute php scripts.
i played with this stuff for weeks, just because i wanted to learn more about http and sockets, its all good fun, but a little too much work for me. well, at the moment anyway.
might give you some ideas.