Reputation: 21
I am trying to make a webpage from where people can run moss and check similarities in source code files.
For that I'm uploading the files via php and calling the moss script with those files as arguments using 'exec' in php, and dumping the output in a separate text file. The code works fine sometimes but sometimes it just stops after uploading the files.
Following is a snippet from the script
$server = 'moss.stanford.edu';
$port = '7690';
.
.
$sock = new IO::Socket::INET (
PeerAddr => $server,
PeerPort => $port,
Proto => 'tcp',
);
die "Could not connect to server $server: $!\n" unless $sock;
$sock->autoflush(1);
.
.
it is unable to create connection, and doesn't proceed beyond the fourth line in this snippet - 'die "Could not connect to server $server: $!\n" unless $sock;'
this doesn't happen all the time but, sometimes it works just fine and sometimes it doesn't.
But when I login to my webhost (which is btw godaddy), via ssh and execute the script in terminal with the same arguments, it always works!
Can someone please help me out with this, what's going wrong on the server sometimes that the script dies when executed through browser?
Upvotes: 2
Views: 4664
Reputation: 103
After DAYS of researching this error ... and confirming that my code and the server settings were all perfect, the reason for the "Connection refused" error is due to shared server issues versus a blocked port.
Meaning... Hosting companies such as Hostgator and GoDaddy block MANY ports!! This is understandable due to security issues. You cannot simply choose a port on the remote server that you would like to use.
The method for testing your server/client/port/script is to OPEN the remote server's port using a more commonly used port. (i.e.: 8080, 80, etc.) Since opening these ports is a security risk, keep the port open only as long as it takes to test the script, then close it again.
If your script processes correctly, then, you need to find a port that your shared hosting company does not block.
*One more tip: It is also possible that a shared hosting company has proxies. This can add to more 'blocking/connection' problems.
I hope this alleviates others from spending the countless hours that I spent trying to solve this problem.
Upvotes: 2
Reputation: 164829
Since it works fine on another machine the problem likely lies in either your network or the particulars of your Perl install or something to do with the browser/PHP interaction. The easiest thing to check is if its your network.
See if you can reproduce the network problem with something other than Perl. Perhaps telnet moss.stanford.edu 7690
a bunch of times. This would determine if the problem is Perl or if your network connection is just flaky.
I'd also leave a ping moss.standford.edu
running and try to reproduce the problem in the browser. If the ping drops out at the same time as you have your problem, there you go, it's a network issue.
Upvotes: 2