..a dose of zero-day know-hows ..

11/20/2008

php fsockopen problems when connecting to ssl and tls mail servers

Few weeks ago I was stumped by some error that took me sometime to resolve concerning PHP Mailer - having it fetch emails from Gmail. After grepping through logs, I discovered few fsockopen errors stating wrong function parameter issues. The logs states:


Warning: fsockopen() expects parameter 2 to be long

I have gone and checked if the PHP Mailer version I use supports connecting via SSL, and it appeared it didn't, in effect I upgraded PHP Mailer to version 2.03. Everything worked fine in my local development server, but behold, yet another error only occurring in our live server, it was:


Warning: fsockopen() [function.fsockopen]:
unable to connect to ssl://smtp.gmail.com:465
(Unable to find the socket transport "ssl" -
did you forget to enable it when you configured PHP?)

The error message was obvious enough for me to realize that I did not compile the php on our server with ssl support. The final resolution was I re-compiled PHP with the following params:


'./configure'
'--with-apxs2=/usr/local/apache2/bin/apxs'
'--with-mysql=/usr/local/mysql/'
'--enable-mbstring'
'--with-gd'
'--with-jpeg-dir=/usr/local/lib'
'--with-png-dir=/usr/local/lib'
'--with-zlib' '--with-curl'
'--with-gettext'
'--with-ncurses'
'--with-imap=/usr/local/imap/imap-2006c1/'
'--with-imap-ssl=/usr/local/ssl/'
'--with-openssl'
'--enable-sockets'

The '--with-openssl' part was just what I needed. After recompiling and restarting httpd, everything worked fine.

No comments: