0

I have googled around it and did not find much around it. There was one question on stack overflow regarding simple socket written in C to SSL socket, but i want that in PHP.

I am using a HTTP server written in PHP, whose details can be found in SocketDaemon.php in this link. The problem is that it is a simple http server with simple read writes which i want to wrap and make an SSL connection to this server, and make it listen to port 443.

Can i have some pointers on how to go about it.

Community
  • 1
  • 1
prat0318
  • 571
  • 1
  • 8
  • 19
  • possible duplicate of [TLS with php server socket](http://stackoverflow.com/questions/4746402/tls-with-php-server-socket) -- Could however check if this snippet works for your case: http://www.php.net/manual/en/function.stream-socket-server.php#98616 – mario Oct 24 '11 at 11:22
  • While you cannot do it in PHP and wrap a socket connection you are reading from, you could still setup your daemon to use `stunnel` – mario Oct 24 '11 at 11:22
  • @mario, thanks I will surely have a look and get back. Just a quick query, using stunnel, will outside browser client think that it is a ssl secured connection and actually it might be just a medium sitting in between. If that is so, this should work for my case. – prat0318 Oct 24 '11 at 11:28
  • It's indeed the easiest approach. You can keep your daemon script as is, but set up a transparaent proxy / port forwarder with SSL using `stunnel -T -d 443 -r 8080`. So the daemon script would be available on port 443 with SSL to browsers, or on the unencrypted own port (unless firewalled). – mario Oct 24 '11 at 11:41
  • Firstly, PHP is not a good language to write an HTTP server in, because it is very difficult to make it work in serving more than one request at once, because it does not support multi-threading and it's non-blocking methods can be very confusing/hard to understand when compared to other languages. Use something like Node.js instead. But secondly, [`stream_socket_server()`](http://www.php.net/manual/en/function.stream-socket-server.php) can be used to take a lot of the pain out of creating/managing an encrypted listen socket in PHP. – DaveRandom Oct 24 '11 at 11:55
  • @DaveRandom Thanks. Currently i am looking for a short term solution in php. Later i am thinking to something scalable. So the options i will be looking at will be `stream_socket_server()` and `stunnel` – prat0318 Oct 24 '11 at 12:01

1 Answers1

0

stunnel totally worked in this case. It listened on 443 port and connected to 80 port internally, just what i wanted.

prat0318
  • 571
  • 1
  • 8
  • 19