2

我正在尝试制作一个网页,人们可以在其中运行moss并检查源代码文件中的相似性。
为此,我通过 php 上传文件并使用 php 中的“exec”以这些文件作为参数调用moss 脚本,并将输出转储到单独的文本文件中。该代码有时可以正常工作,但有时它会在上传文件后停止。
以下是脚本的片段

$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);
.
.

它无法创建连接,并且不会超出此代码段中的第四行 - ' die "Could not connect to server $server: $!\n" unless $sock; '

这并不总是发生,但有时它工作得很好,有时却不行。
但是,当我通过 ssh 登录到我的网络主机(顺便说一句,godaddy)并在终端中使用相同的参数执行脚本时,它总是有效的!

有人可以帮我解决这个问题,服务器上出了什么问题,有时脚本在通过浏览器执行时会死掉?

4

2 回答 2

2

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.

于 2013-08-28T06:39:47.917 回答
2

由于它在另一台机器上运行良好,因此问题可能出在您的网络或 Perl 安装的细节上,或者与浏览器/PHP 交互有关。最容易检查的是它是否是您的网络。

看看你是否可以用 Perl 以外的东西重现网络问题。也许telnet moss.stanford.edu 7690是好几次。这将确定问题是 Perl 还是您的网络连接不稳定。

我还会ping moss.standford.edu继续运行并尝试在浏览器中重现问题。如果在您遇到问题的同时 ping 掉线了,那就是网络问题。

于 2012-11-02T19:58:26.733 回答