tags:

views:

87

answers:

3

I'm trying to connect to gmail pop server from a phplist installation and it fails, but i'm not sure whether my webhost opened port 995 or not. They say they have opened it, but i'm in doubt. Is there a way i can check it from a php script? They are running php 5.2.0 on a windows server, though i'm not sure what OS is that. phpinfo() says "Windows NT DEDI514 5.2 build 3790"

A: 

I think you'll need to ping or traceroute to a machine that will respond on that port.

This article should have much more than you want to know, but there's an example script at the bottom that you can modify to test.

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=8&txtCodeId=1786

There are some other scripts here: http://www.theworldsend.net/

I can't vouch for any of these personally, but they look like what you need.

And, of course, if you can ssh or telnet into your server, you can do all this much more easily using the ping and traceroute commands.

Scott Saunders
+2  A: 

You can put code in a php script to open a connection to a specific hostname (or IP address) and port. If you know the expected response, you should be able to tell if you are getting a connection. If you get something like "Connection refused", then either you are being blocked, or the destination host is not accepting connections on that port.

This example uses IP address 192.0.2.0 and port 995. Replace these with whatever you want to test.

<?php
    echo "\nOpening connection\n\n";

    $fp = fsockopen("192.0.2.0", 995, $errno, $errstr);
    if (!$fp) {
        echo "ERROR: $errno - $errstr\n";
    } else {
        echo fread($fp, 1024);
        fclose($fp);
    }
?>

You can also send data to the server using

fwrite($fp, "blah blah blah\r\n");

There is more information about fsockopen here.

bmb
A: 

Maybe safe mode is active? This prevents calling services on other servers.

Edit: All filesystem and stream functions are affected by the safe mode settings!

The open_basedir setting affects fopen()!

powtac
I think you mean "safe mode". Are you sure it prevents calling services on other servers?
bmb
Er, yes, "Safe Mode"
powtac
powtac, I have just run a test and I am able to call fsockopen with safe mode on. Also, I can call file_get_contents on a URL successfully. I don't see where in the documentation you link to it says that safe mode prevents calling services on other servers.
bmb
http://de.php.net/manual/en/function.fopen.php says:If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply.
powtac
powtac, I don't see how that relates to calling services on other servers. I don't think fopen is relevant, there are no local files involved, and my test shows other servers *can* be contacted in safe mode.
bmb