Page 1 of 1
PHP5 and sending email
Posted: Wed Mar 17, 2004 11:18 am
by Crucial
Just curious if anyone knows if the release of PHP 5 will fix the email issues with PHP on Solaris (which restrict the use of fopen()/fdopen() to 255 files)? [
http://bugs.php.net/bug.php?id=25195 ]
I realize this seems to be a Solaris issue and not PHP, but was curious to know if there was a change in PHP that might fix this (sinc it appears the guys at Sun don't plan on doing anything about it).
Thanks in advance.
-Dave
Posted: Wed Mar 17, 2004 11:20 am
by patrikG
hmm, for some reason I get a timeout on that link

Posted: Wed Mar 17, 2004 11:26 am
by Crucial
wierd...seems to work on my end. In any event here's a basic description of th problem as written by an Engineer at Sun (i think):
"Looking at the PHP source code I can see that sendmail is being invoked by the popen() function. This uses the standard I/O library (stdio) to communicate over a stream and pass information to sendmail. By choosing a stdio function the programmers have limited themselves to a maximum of 255 file descriptors. If you look at the stdio(3C) man page you can see this is clearly documented:
The integer constant FOPEN_MAX specifies the minimum number of files that the implementation guarantees can be open simultaneously. Note that no more than 255 files may be opened using fopen(), and only file descriptors 0 through 255 can be used in a stream.
In the truss you have supplied it's possible to see that popen is asking for and getting a couple of file descriptors, which are over this 255 limit:
2654/12: 14.7296 pipe() = 262 [263]
2654/12: 14.7301 close(263) = 0
2654/12: 14.7304 close(262) = 0
.
.
.
2654/12: 26.8940 pipe() = 265 [266]
2654/12: 26.8944 close(266) = 0
2654/12: 26.8947 close(265) = 0
The reason why this is failing is that the iPlanet Web Server has increased the soft file descriptor limit to 1024, thus allowing fd numbers > 255. Unfortunately this behaviour is detramental to popen() and breaks functions that depend upon the stdio library.
Now then you won't see the problem initially as calls to popen() will return a file descriptor < 255, however over time as file descriptors are used up and processes hold open file descriptors you'll start to creap up to this 255 limit and that's when things will break."
Their suggestions to resolve this were as follows:
"I do have one workaround but the "cure" could be worse than the symptoms. I was talking with the iPlanet/SunONE folks about this yesterday. One of the main reasons that the Web Server increases the file descriptor limit is to allow more sockets to be created.
By restricting the file descriptor limit to 256 you are seriously hampering the number of clients that can connect and will artificially limit the web server as it reaches 256 file descriptors and then stops serving pages, until a free descriptor becomes available.
It's a difficult one to call but ultimately I believe PHP are at fault for using a programming method that is well known to have limitations on the number of file descriptors it can open. Seeing as this is supposed to be run within the confines of the web server it should not assume that there will only be 256 file descriptors available to it.
The authors of PHP need to rewrite their code to work around this 256 fd limit."