Couple of reasons for this, but both point to the php.ini files that are being used by Apache and the CLI. Look at the output of a phpinfo() for each to see the differences.

Now, I suspect that either warnings are not set to display on the CLI and you actually do still have the warning (you can check the logs to see if the warning shows there) or the CLI php.ini file has different settings regarding the socket connections.

    Hi Ashley

    Thank you for the very quick response. I did check the error levels. What i have posted is just the fsockopen part of the code. The entire code uses fsockopen to send emails and the email goes through perfectly when i execute the PHP from the command line.

    However, when I access through a browser, then i get the connection refused error.

    My IT support guy insists that there are no firewall issues :-(

    Any ideas please?

    Thanks again

      What are the differences between the two php.ini files that are used by Apache and the CLI, as I think will shed some light on this.

        Hi again

        I output from the command line and saved from the browser as a text file, ran kdiff on that and both files are binary equal!! Same content!

        The IT guys say that there's no firewall installed on it. I saw microsoft firewall service running, and stopped it but i still get the same error

        I don;'t know if there's a specific configuration for Apache on windows to allow fsock?

          I don't believe so, this has me stumped for the moment. Maybe one of the other guys here has more of an idea?

            This might sound like a silly question, but have you disabled the firewall on both machines? This is the firewall on the machine running Apache and the firewall on the machine running the remote service that you're trying to socket to.

              I think there's something here: i had cross posted on another forum.

                Yeah, I saw that, but you've only mentioned about one firewall. As far as I can tell, there are 3 machines involved in this. Your computer (doesn't matter about any firewall here, as you are only communicating over port 80 and that seems to work), the server that is running the PHP code and the server that your trying to connect to with that PHP code. It's the firewalls on those servers that you need to check, because one could exists that is stopping certain kinds of outbound traffic, etc.

                  The one plausible explanation I was going to suggest after reading your first post was the one already mentioned at StackOverflow:

                  Sounds to me like php.exe is allowed to make outgoing connections, and httpd.exe is not.

                    After several tries with different IP addresses, i realised that the only problem was with fsockopen on port 25. It works well with command line interface but didn't work through the web browser. PHP was earlier installed in windows as CGI. I thought i will see if it still doesn't work when set up as an Apache handler and it works! http://www.php.net/manual/en/install.windows.apache2.php .

                    Hope this helps someone in future.

                      Write a Reply...