PHP流套接字客户端 - 无效的IP地址

My server has multiple IP address, and I use this code to bind IP to stream socket client. It works fine. But some time I get this warning:

stream_socket_client(): Invalid IP Address:

I'm using PHP 5.3.3 and my server is running CentOS 5.x

    $opts = array(
    'socket' => array(
        'bindto' => '1.1.1.1:0',
    ),
);


// create the context...
$context = stream_context_create($opts);
$fp = @stream_socket_client ( $link, $errno, $errstr, 120, STREAM_CLIENT_CONNECT, $context);

Can you tell me how to avoid this warning. Thank you very much!!!


UPDATE

Code as requested by a comment below:

if (function_exists('stream_context_create')
    && function_exists('stream_socket_client')
) {
    $socket_options = array('socket' => array('bindto' => $ip .':0'));
    $socket_context = stream_context_create($socket_options);
    $this->smtp_conn = stream_socket_client(
        "$host:$port",
        $errno,
        $errstr,
        30,
        STREAM_CLIENT_CONNECT,
        $socket_context
    );
} else {
    $this->smtp_conn = @fsockopen($host, $port, $errno, $errstr, $tval);
}

That is an invalid IP address... you'll also need a correct port.

If you are connecting to your local machine, the IP will be 127.0.0.1