Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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

share|improve this answer
    
If it is possible, I find it hard to believe that noone tried though. –  mafutrct May 18 '11 at 12:40
3  
cough Well, the people capable of writing a mail server probably don't use PHP that much... –  Ignacio Vazquez-Abrams May 18 '11 at 12:49
1  
It would be easier to move to a host that offers more flexibility/functionality. –  Linker3000 May 18 '11 at 12:58
    
@Linker3000: For certain reasons, moving is not an option in my case. –  mafutrct May 18 '11 at 15:26
add comment

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.

share|improve this answer
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. –  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. –  mafutrct May 18 '11 at 15:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.