Код: Выделить всё
class SMTPclient{
private $address;
private $port;
private $sock;
function Init($address="localhost", $port=25)
{
$this->address = $address;
$this->port = $port;
echo 'Create socket ...';
$this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($this->sock < 0)
throwException('socket_create() failed: ');
else
echo "OK\n";
}
function Destroy()
{
if (isset($this->sock)) {
echo 'Close socket ... ';
socket_close($this->sock);
echo "OK\n";
}
}
function setAddress( $address ){ $this->address = $address; }
function getAddress( $address ){ return $this->address; }
function setPort( $port ){ $this->port = $port; }
function getPort( $port ){ return $this->port; }
function Connect()
{
echo "Connecting to socket at $this->address : $this->port ... ";
$result = socket_connect($this->sock, $this->address, $this->port);
if ($result === false)
throwException('socket_connect() failed: ');
else echo "OK\n";
}
function ReadResponse()
{
$out = socket_read($this->sock, 256);
return $out;
}
function SendRequest($msg)
{
socket_write($this->sock, $msg, strlen($msg));
}
}
Код: Выделить всё
$smtp = new SMTPclient("localhost", 25);
try {
$smtp->Init();
$smtp->Connect();
echo $smtp->ReadResponse();
echo "Say to server EHLO localhost...\n";
$smtp->SendRequest("EHLO localhost");
echo $smtp->ReadResponse();
$smtp->Destroy();
} catch (Exception $e) {
echo "\nError: ".$e->getMessage();
}
Проделывая это всё через telnet проблем нет. С чем может быть связано такое долгое время ответа от сервера?