6

I would like to set up an mail server on one of my hosted machines that only supports PHP. There is no standard mail server running on that machine.

Are there any mail servers written in PHP? Or, is it even possible to write a mail server in PHP in regards to the limitations of the language?

mafu
  • 2,865
  • 6
  • 30
  • 36

2 Answers2

4

Your fundamental problem is going to be that even if you wrote or found a mail server implemented in PHP, you're not going to be able to run it on your host.

  • The web server executing your PHP scripts is listening on port 80 (and maybe 443), not 25, 587, or 465.
  • The scripts will get terminated by the web server after running too long or using too much RAM.
  • You're not going to be able to run the script as a service on the host.
  • Even if you could, most will have resource monitors that kill long-running scripts.
  • Even if that weren't an issue, root privileges are normally required to listen on low-numbered (< 1024) ports.

Edit: All of the above assume shared hosting. Of course, most of these constraints go away with a VPS. However, in that case you can install proper mail servers so it doesn't really matter anyway.

Beyond all that, there's no particular reason that nobody's bothered writing a mail server in PHP, it's just that it's not a particularly useful endeavor.

@Linker3000 has it right in @Ignacio's answer: Move to a host that gives you what you want.

afrazier
  • 22,987
  • 3
  • 60
  • 88
  • 2
    +1, but you are making some incorrect assumptions about PHP. Re #1: stream_socket_server() and socket_accept() (although #5 applies, of course). Re #2: PHP scripts are not necessarily CGI; they can be run from command line or in background, given necessary access. – u1686_grawity May 18 '11 at 14:08
  • @grawity: I'm aware that PHP doesn't necessarily mean "CGI", but is it possible to have a PHP script running as a CGI listen on another port? I've never needed to try. All the other items are still problems though. You did make me think of something else though... edit upcoming. – afrazier May 18 '11 at 14:54
  • The service I'm using is cloud hosted. Sadly I don't know if I am technically to use any port, but personally, I would not mind setting the used port in my email client to something nonstandard at all. – mafu May 18 '11 at 15:28
3

It is theoretically possible, but no one does it since a mail server is a large, complex beast and there are already so many available written in other languages

Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247