Search code examples
phpsocketsipfsockopen

Set ip for socket PHP


Im using the following function for socket :

if (function_exists('stream_context_create') && function_exists('stream_socket_client')) {
    $socket_options = array('socket' => array('bindto' => '192.0.2.1:0'));
    $socket_context = stream_context_create($socket_options);
    $socket = stream_socket_client('ssl://xmlapi.example.org:9090', $errno,
        $errstr, 30, STREAM_CLIENT_CONNECT, $socket_context);
} else {
    $socket = @fsockopen( "ssl://xmlapi.example.org" , 9090 , $errno , $errstr , 30 );
}

But IP dont change, its still shows server IP but functions are exist and 1st case it executing.


Solution

  • Short answer: You can't. Because the server is not the client.

    Long answer: You can by creating custom packets in C, but you won't get two-way traffic. Because the server is not the client.